簡體   English   中英

在二維numpy數組中找到滿足條件的值的索引

[英]Find the indices of values fulfilling condition in 2d numpy array

我有一個2D值數組,我想找到值大於最大值60%的索引。 我努力了:

: nmax, nmin = np.amax((n[:,:])),np.amin((n[:,:]))
: np.unravel_index(n[n>0.6*nmax], n.shape)

但是我得到了錯誤:

TypeError: Iterator operand 0 dtype could not be cast from dtype('>f4') to dtype('int64') according to the rule 'same_kind'

任何見識將不勝感激。

如上所述,使用np.where()像這樣:

    x = np.random.randint(0,50,(20,20))
    y = np.where(x>0.6*np.max(x))

y將作為具有兩個表示數組的兩個軸的數組的元組給出,但是您可以使用y,但是您需要例如x [y]將返回x的值,所有x的值都將大於0.6 * max。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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