[Numpy-discussion] Truth value of an array
Fri Apr 18 07:43:40 CDT 2008
2008/4/18, Olivier Verdier <email@example.com>:
> I certainly didn't mean that "A==B" should return a boolean!!
> "A==B" should return an array of boolean as it does now. This is all
> *However* "bool(A==B)" should return a boolean, *not* raise an
> exception. Why raise an exception? What is ambiguous about
> This is what happens when you write "if A==B" because then
> "bool(A==B)" is somehow triggered and bang, an exception is raised.
> As I tried to explain, the default behaviour should be that "bool(A)"
> return "A.all()" but not an exception. Why is there an exception
> raising at all?
Sometimes, you want .all(), sometimes .any(). It really depends on the
question you are asking. Even for bool(A), there is no easy answer. In some
case I want True if some elements are true, in other cases only if all
elements are true.
I would agree with you some years ago, but after using bool(A) = A.all(), I
started noticing that it brakes my coding instead of speeding it and does
not give me any benefit at all.
French PhD student
Website : http://matthieu-brucher.developpez.com/
Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn : http://www.linkedin.com/in/matthieubrucher
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion