[Numpy-discussion] improved NumPy support for boolean arrays?
Sturla Molden
sturla@molden...
Wed Aug 5 16:02:04 CDT 2009
> If x and y are numpy
> arrays of bools, I'd like to be able to create expressions like the
> following:
>
> not x (to invert each element of x)
> x and y
> x or y
> x xor y
> (not x) or y
>
> The usual array broadcasting rules should apply. Is there any chance of
> getting something like this into NumPy?
There is a reason for this related to Python. In Python an object will
often have a boolean truth value. How would you cast an ndarray to bool?
If you write something like (x and y) the Python interpreter expects
this to evaluate to True or False. Thus is cannot evaluate to an ndarray
with booleans. NumPy cannot change the syntax of Python.
Another thing: An empty list evaluates to False in a boolean context,
whereas a non-empty list evaluates to True. ndarrays behave differently.
Why?
Sturla Moldem
More information about the NumPy-Discussion
mailing list