[Numpy-discussion] Why is the truth value of ndarray not simply size>0 ?
Alan G Isaac
aisaac@american....
Sun Sep 13 08:05:41 CDT 2009
On 9/13/2009 7:46 AM, Robert wrote:
> 2 ways seem to be consistently Pythonic and logical: "size>
> 0"; or "any(a)" (*); and the later option may be more 'numerical'.
Well, *there's* the problem.
As a user I have felt more than once that a
length based test, like other containers, would
be natural, so I that I could do the usual test
if a:
That would certainly prove problematic for
the `any` test when a is an array of zeros.
And then soon after I want to use
if (a>0):
and that would certainly prove problematic for
the `len` test when (a>0) is an array of zeros.
And as for the `any` test, well in this case I
usually want `all`.
So the ValueError has proved useful.
Alan Isaac
More information about the NumPy-Discussion
mailing list