簡體   English   中英

使用numpy索引的元組

[英]Tuple to index using numpy

它使我發瘋,但我無法弄清楚我的數據矩陣為(10000,4)

我需要選擇一些行,其中列0的元素

ind1=np.where( (data[:,0]>55) & (data[:,0]<65) )

我只想保留這些數據

keep_data=data[ind1,:]

但是keep_data現在是(1,10000,4)

這是為什么?

PS我正在做的事

keep_data=np.reshape(keep_data,(keep_data.shape[1],keep_data.shape[2]))

numpy.where返回一個元組。

因此,使用ind1 = np.where((data[:,0]>55) & (data[:,0]<65))[0]

注意[0]索引選擇了元組的唯一元素。

文檔中對此進行了說明:

numpy.wherecondition [,x,y]

根據條件從x或y返回元素。

如果僅給出條件,則返回元組 condition.nonzero() ,其中condition為True的索引。

暫無
暫無

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

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