[Numpy-discussion] question about nonzero behavior in numarray

Colin J. Williams cjw at sympatico.ca
Thu Apr 1 15:00:00 EST 2004

Perry Greenfield wrote:

>Todd pointed out to me that he's gotten some complaints about
>the difference in how numarray nonzero behavior works.
>In version 0.9 the use of an array for a truth value was
>changed from a deprecation warning to an exception.
>We deprecated it because the meaning of an array as a truth
>value was ambiguous (or potentially confusing at best)
>and we felt it was better to force users to be explicit
>about what they wanted. Nevertheless, Numeric does allow that
>and removing the capability to use it in that context breaks
>some code. 
>We can give some thought to reversing that decision, but since
>we only hear from those that don't like the new behavior, we'd
>like to get some sense if there are many that do like the new
>To clarify, what happens when:
>x = zeros(2)
>if x:
>    print "true!"
>I see 3 possibilities:
>1) Keep it the way it is, no use of an array is permitted; an 
>   exception is raised.
>2) Print a warning message when it is used that way, and always
>   keep it at that, i.e., warning message only.
>3) Replicate Numeric behavior.
>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). 
>[Option 2 on the previous question wins hands down]
I favour option 1, otherwise there is a need to define just what it means.

Does it return a Boolean array indicating those cells which are nonzero, or
a single Boolean value indicating that some cell is nonzero, or a single
Boolean value indicating that all cells are nonzero?

Colin W.

>This SF.Net email is sponsored by: IBM Linux Tutorials
>Free Linux tutorial presented by Daniel Robbins, President and CEO of
>GenToo technologies. Learn everything from fundamentals to system
>Numpy-discussion mailing list
>Numpy-discussion at lists.sourceforge.net

More information about the NumPy-Discussion mailing list