Numpy - delete data rows with negative values

Viewed 5432

I am taking the output from AUTO numerical continuation package, and need to filter out results that have negative values of the variables, as they are non-physical. So if I have, for example:

>>>   a = np.array([[0,1,2,3,4],[-1,-0.5,0,0.5,1],[-3,-4,-5,0.1,0.2]])

I would like to be left with:

>>> b
array([[ 3. ,  4. ],
       [ 0.5,  1. ],
       [ 0.1,  0.2]])

But when I try numpy.where I get:

>>> b = a[:,(np.where(a[1]>=0) and np.where(a[2]>=0))]
>>> b
array([[[ 3. ,  4. ]],

       [[ 0.5,  1. ]],

       [[ 0.1,  0.2]]])
>>> b.shape
(3, 1, 2)

That is, it adds another unwanted axis to the array. What am I doing wrong?

2 Answers
Related