Numpy: Filtering Rows By Multiple Conditions?
I have a two-dimensional numpy array called meta with 3 columns.. what I want to do is : check if the first two columns are ZERO check if the third column is smaller than X Return
Solution 1:
you can use multiple filters in a slice, something like this:
x = np.arange(90.).reshape(30, 3)
#set the first 10 rows of cols 1,2 to be zerox[0:10, 0:2] = 0.0x[(x[:,0] == 0.) & (x[:,1] == 0.) & (x[:,2] > 10)]#should give only a few rows
array([[ 0., 0., 11.],
[ 0., 0., 14.],
[ 0., 0., 17.],
[ 0., 0., 20.],
[ 0., 0., 23.],
[ 0., 0., 26.],
[ 0., 0., 29.]])
Post a Comment for "Numpy: Filtering Rows By Multiple Conditions?"