![](/img/trans.png)
[英]output of numpy.where(condition) is not an array, but a tuple of arrays: why?
[英]Why does numpy.where() give two arrays with an array of more than 1 row as input?
我了解np.where()
的 output 输入单行数组。 但是,当使用两行数组作为输入时,我不明白为什么 b 的 output 是两个 arrays。
a[b] 的 output 是有意义的。
a = np.array([[1, 2, 3],[4,5,6]])
print(a)
print ('Indices of elements <4')
b = np.where(a<4)
print(b)
print(a[b])
output 用于 b:
(array([0, 0, 0], dtype=int64), array([0, 1, 2], dtype=int64))
output 用于 a[b]:
[1 2 3]
我们需要两个索引来访问二维数组中的每个元素。 例如。 我和 j。 因此,如果满足条件的二维数组的索引是(i1,j1), (i2,j2) and (i3,j3)
条件a<4
,则np.where()
将返回格式为元组的元组像((i1,i2,i3),(j1,j2,j3))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.