[英]Index a numpy array using a tuple (or list) when len < ndim?
[英]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.where ( condition [,x,y] )
根据条件从x或y返回元素。
如果仅给出条件,则返回元组
condition.nonzero()
,其中condition为True
的索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.