[Numpy-discussion] Truth value of an array
Fri Apr 18 15:39:04 CDT 2008
On Fri, Apr 18, 2008 at 3:33 PM, Joe Harrington <firstname.lastname@example.org> 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.
"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