簡體   English   中英

為什么 numpy.where() 會給出兩個 arrays 作為輸入?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM