[Numpy-discussion] Truth value of an array

Olivier zelbier@gmail....
Fri Apr 18 08:36:23 CDT 2008


Let's restrict the discussion the case to boolean arrays (dtype bool),
since all the comparisons (A==B, A!=B, A<B etc. return boolean
arrays).

So I have an array filled with booleans. Is there a reason not to map
"bool(A)" to "A.all()" but instead raise an exception?

As far as I can see, "if A==B" is clear enough; one always means
"(A==B).all()". Isn't that so?

I would like to see examples where there is clearly an ambiguity so
that I understand the benefit of having an exception raised for
boolean matrices instead of simply using all().

If there is no such clear example, then why not map "bool(A)" to
"A.all()" in numpy?

Thanks!

On 18 avr, 15:20, Alan G Isaac <ais...@american.edu> wrote:
> On Fri, 18 Apr 2008, Olivier Verdier apparently wrote:
> > What is ambiguous about "bool(A==B)"?
>
> A==B is an array. Compare:
>
>     >>> bool([])
>     False
>     >>> bool([0])
>     True
>
> Even if you decide the second should be false,
> what about [0,1]?  (I.e., all or any?)
>
> Cheers,
> Alan Isaac
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discuss...@scipy.orghttp://projects.scipy.org/mailman/listinfo/numpy-discussion


More information about the Numpy-discussion mailing list