It drives me crazy, but I can't figure it out I have a data matrix of (10000,4)
I need to select some rows where the elements of column 0
ind1=np.where( (data[:,0]>55) & (data[:,0]<65) )
I want to keep that data only so
keep_data=data[ind1,:]
But keep_data is now (1,10000,4)
Why is that?
PS What i do is th efollwing
keep_data=np.reshape(keep_data,(keep_data.shape[1],keep_data.shape[2]))
numpy.where
returns a tuple.
Therefore, use ind1 = np.where((data[:,0]>55) & (data[:,0]<65))[0]
Notice the [0]
indexing to select the only element of the tuple.
This is noted in the docs :
numpy.where ( condition[, x, y] )
Return elements, either from x or y, depending on condition.
If only condition is given, return the tuple
condition.nonzero()
, the indices where condition isTrue
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.