python numpy如何增加给定的索引
我有一个方法location,它在2d阵列板上查找一个工件的位置,我想将索引更改为它旁边的位置python numpy如何增加给定的索引,python,arrays,numpy,indexing,tuples,Python,Arrays,Numpy,Indexing,Tuples,我有一个方法location,它在2d阵列板上查找一个工件的位置,我想将索引更改为它旁边的位置 def location(self, board): x = np.argwhere(board == 1) print(x) return x x = self.location(board + 1) 如果我正确地解释了您的问题,您只需要将+1从括号中移出: def location(self, board): x = np.argwhere(board == 1
def location(self, board):
x = np.argwhere(board == 1)
print(x)
return x
x = self.location(board + 1)
如果我正确地解释了您的问题,您只需要将+1从括号中移出:
def location(self, board):
x = np.argwhere(board == 1)
print(x)
return x
x = self.location(board) + 1
在这个问题中,您所做的是向电路板本身添加1,而不是向您所看到的返回索引添加1,这是一个2d数组(2列,对吧?)。因为它是一个数组,所以可以对它进行普通的数学运算,例如将1添加到
x[0,1]
。y=np的结果。其中(board==1)
更易于使用,如在board[y]
中,但是相同的信息在argwhere
中。发布的代码没有正确缩进。