例如,我有一个数组和它的索引:
xx = np.arange(6).reshape(2,3)
index = np.argwhere(xx>3)
如果我使用
xx[index]
我遇到了一个错误:
IndexError: index 2 is out of bounds for axis 0 with size 2
但是如果我写:
xx[index[0], index[1]]
我得到:
array([4, 5])
这正是我想要的,但如果我有一个 N 维数组,我需要写什么呢?
xx[index[0], index[1], ..., index[N]]
在这种情况下,还有更好的方法吗?
xx[xx>3]
? - user2357112index
。 - f. c.xx[tuple(index)]
对我来说可行。 - Karl Knechtel