[英]numpy where: how to find a 2D array's index in a 3D array by matching a 1D array?
a = np.array([[[1,2,3], (1,1,0,0,8)], [[1,2,3], (1,1,2,0,8)], [[1,2,3], (4,1,0,0,8)]])
where = np.where(a[:,1] == (1,1,0,0,8))
print(where)
输出:
(array([], dtype=int64),)
我想要它 output 0
,出现(1,1,0,0,8)
的行的索引
NumPy 通常将元组解释为数组或数组的子集而不是元素,但您可以通过以下方式绕过它:
el = np.array([None], dtype = object)
el[0] = (1,1,0,0,8)
where = np.where( a[:,1] == el ) # outputs a tuple: (array([0], dtype=int64),)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.