Multiple conditions using 'or' in numpy array

There's numpy.logical_or

http://docs.scipy.org/doc/numpy/reference/generated/numpy.logical_or.html

numpy logical_and and logical_or are the ufuncs that you want (I think)

Note that & is not logical and, it is bitwise and. This still works for you because (a>10) returns a logical array (e.g. 1's and 0's) as does your second condition. So, in this case, "logical and" and "bitwise and" are equivalent (same with logical and bitwise or). But in other cases, the bitwise operations may yield surprising results (mostly because python's & and | operators have lower precedence than expected in these contexts).


If numpy overloads & for boolean and you can safely assume that | is boolean or.

area1 = N.where(((A>0) & (A<10)) | ((A>40) & (A<60))),1,0)

Tags:

Python

Numpy