[Numpy-discussion] dtype and logical_and

Keith Goodman kwgoodman@gmail....
Thu Jan 28 10:31:44 CST 2010


I noticed that & (logical and) does support float dtype:

>> b = np.array([True, False])
>> f = np.array([1.0, 2.0])
>> i = np.array([1, 2])

>> b & b
   array([ True, False], dtype=bool)
>> i & i
   array([1, 2])
>> i & f
TypeError: unsupported operand type(s) for &: 'int' and 'float'

But this works:

>> np.logical_and(b, f)
   array([ True, False], dtype=bool)

and this gives a different result from i & i above:

>> np.logical_and(i, i)
   array([ True,  True], dtype=bool)

Why are & and np.logical_and different?

If I have a class (a labeled array, larry) any suggestions on whether
I should use & or np.logical_and on the the underlying arrays for the
__and__ method?


More information about the NumPy-Discussion mailing list