numpy fromstring贬值,改用frombuffer

问题描述 投票:0回答:1

在使用numpy 1.18.1的Python代码中]

`def printBoard(self):当前= self.player其他= self.player%2 +1

    currBin   = '{:049b}'.format(self.current_position)
    currRev = currBin[::-1]

    cArr = (np.fromstring(currRev,'u1') - ord('0'))*current

    other_position = self.current_position^self.mask
    othBin   = '{:049b}'.format(other_position)
    othRev = othBin[::-1]

    oArr = (np.fromstring(othRev,'u1') - ord('0'))*other

    tArr =  oArr+cArr

    brd = np.reshape(tArr,(7,7),order = 'F')
    for y in range(bitBoard.HEIGHT,-1,-1):
        for x in range(bitBoard.WIDTH):
            print(brd[y,x],end = ' ')
        print()
    print()
    `

行:

cArr = (np.fromstring(currRev,'u1') - ord('0'))*current

给出以下警告:

DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on    unicode inputs. Use frombuffer instead
  cArr = (np.fromstring(currRev,'u1') - ord('0'))*current

用'frombuffer'替换'fromstring'会出现以下错误:

cArr = (np.frombuffer(currRev,'u1') - ord('0'))*current

TypeError: a bytes-like object is required, not 'str'

尽管进行了一些Google搜索,但我找不到应该使用的内容。有人可以帮忙吗?

谢谢。

艾伦

在使用numpy 1.18.1`的Python代码中def printBoard(self):current = self.player other = self.player%2 +1 currBin ='{:049b}'。format(self.current_position)currRev =。 ..

numpy
1个回答
0
投票

您的代码的相关部分是产生currRev的部分。由此我可以构建这个示例:

© www.soinside.com 2019 - 2024. All rights reserved.