[Numpy-discussion] question about nonzero behavior in numarray
Fernando.Perez at colorado.edu
Thu Apr 1 14:52:09 CST 2004
Perry Greenfield wrote:
> Personally, I prefer 1) since I think there is too much confusion
> between whether false means an empty (len=0) array (like lists),
> or an array that contains all zeros, and that it is worth breaking
> backward compatibility on this (functions should be used to
> distinguish which meaning is desired).
I tend to prefer keeping compatibility with Python list behavior. I think
that in general, numarray arrays should behave different from lists only when
truly justified (for example, at least in numeric all ufuncs can be applied to
a list of floats as much as to an array, which is nice).
Since anyone who knows python already knows that lists are true based on
whether they contain _anything_:
In : a=
In : b=
In : if a:
....: print 1
In : if b:
....: print 1
then I think it's a fair, clean extension to make NumArray behave similarly.
I think a good guiding principle is to keep the number of special cases for
arrays at a strict minimum (there are obviously cases where it does make sense
to have special cases). Besides, this is an O(1) check, so it doesn't have
the dangers of checking for all elements being zero. Such a potentially
expensive operation should _definitely_ happen only if explicitly requested, IMHO.
More information about the Numpy-discussion