EDIT: Fixed values in tables.
Let\'s say I have a pandas dataframe df:
>>>df
a b c
0 0.016367 0.
It is not possible for custom types to override the behavior of and
and or
in Python. That is, it is not possible for Numpy to say that it wants [0, 1, 1] and [1, 1, 0]
to be [0, 1, 0]
. This is because of how the and
operation short-circuits (see the documentation); in essence, the short-circuiting behavior of and
and or
means that these operations must work as two separate truth values on the two arguments; they cannot combine their two operands in some way that makes use of data in both operands at once (for instance, to compare the elements componentwise, as would be natural for Numpy).
The solution is to use the bitwise operators &
and |
. However, you do have to be careful with this, since the precedence is not what you might expect.