[Numpy-discussion] Re: ***[Possible UCE]*** [SciPy-user] Regarding what "where" returns
Travis Oliphant
oliphant at ee.byu.edu
Wed Apr 12 15:56:03 CDT 2006
Perry Greenfield wrote:
>We've noticed that in numpy that the where() function behaves
>differently than for numarray. In numarray, where() (when used with a
>mask or condition array only) always returns a tuple of index arrays,
>even for the 1D case whereas numpy returns an index array for the 1D
>case and a tuple for higher dimension cases. While the tuple is a
>annoyance for users when they want to manipulate the 1D case, the
>benefit is that one always knows that where is returning a tuple, and
>thus can write code accordingly. The problem with the current numpy
>behavior is that it requires special case testing to see which kind
>return one has before manipulating if you aren't certain of what the
>dimensionality of the argument is going to be.
>
>
I went ahead and made this change to the code. The nonzero function
still behaves as before (and in fact only works for 1-d arrays as it did
in Numeric).
The where(condition) function works the same as condition.nonzero() and
both always return a tuple.
I had to change exactly one piece of code that used the new where syntax.
This does represent a code breakage with the where syntax (but only if
you used the newer, numarray-introduced usage). I think this is a
small-enough segment that we can make this change.
-Travis
More information about the Numpy-discussion
mailing list