簡體   English   中英

numpy在非排序數組上

[英]numpy where on non-sorted array

我想在與列表匹配的numpy數組中找到元素的索引。 我的數組未排序。 到目前為止,我正在使用以下代碼

Y = np.array([ 2,2,1,1,3,1,3,2,-1,-1])
indcs = [np.where(Y == c)[0] for c in range(1,4)]

集成電路

[array([2,3,5]),array([0,1,7]),array([4,6])]

但是我覺得有一種更好的方法來獲取要作為行搜索的每個值的結果,而不是簡單地使用for循環進行迭代。 有人可以幫忙嗎?

此代碼可以為您提供幫助。

    indices=[i for i,v in enumerate(Y.tolist()) if v in range(0,4)]

暫無
暫無

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

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