Skip to content
Advertisement

How find values in an array that meet two conditions using Python

I have an array

JavaScript

and I want to find the indices of the element s that meet two conditions i.e.

JavaScript

I can use numpy.nonzero(a>3) or numpy.nonzero(a<8) but not numpy.nonzero(a>3 and a<8) which gives the error:

JavaScript

When I try to use any or all I get the same error. Is it possible to combine two conditional tests to get the ans?

Advertisement

Answer

JavaScript

& does an element-wise boolean and.

Advertisement