[Numpy-discussion] Truth value of an array
Robert Kern
robert.kern at gmail.com
Fri Apr 18 16:39:04 EDT 2008
On Fri, Apr 18, 2008 at 3:33 PM, Joe Harrington <jh at physics.ucf.edu> wrote:
> For that matter, is there a reason logical operations don't work on
> arrays other than booleans? What about:
The keywords "and", "or", and "not" only work on bool objects; Python
tries to convert the operands using bool(). bool(some_array) raises
the exception just as we've been discussing.
> Here, both x and y are completely True, but you can't trivially do a
> logical AND, and the bitwise & isn't the one you want. You have to
> cast to boolean manually and do the logical instead.
>
> Can this be fixed or is there a reason for the exception?
No, it cannot be fixed. Python does not give us a way to overload the
behavior of these keywords.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the NumPy-Discussion
mailing list