[Numpy-discussion] nonzero() behaviour has changed
Ed Schofield
schofield at ftw.at
Thu May 18 03:40:01 EDT 2006
Bill Baxter wrote:
> Aren't there quite a few functions that return indices like nonzero()
> does?
> Should they all have arg*** versions that just transpose the output of
> the non arg*** version?
>
> Maybe the answer is yes, but to me if all it takes to get what you
> needs is transpose() then I'm not sure how that fails to be obvious.
> You have [[x y z] [p d q]] and you want ([x p][y d][z q]). Looks like
> a job for transpose!
> Maybe a note in the docstring pointing out "the obvious" is what is
> really warranted. As in "hey, look, you can transpose the output of
> this function if you'd like the indices the other way, but the way it
> is it's more useful for indexing, as in a[ a.nonzero()]."
Well, it wasn't immediately obvious to me how it could be done so
elegantly. But I agree that a new function isn't necessary. I've
re-written the docstring for the nonzero method in SVN to point out how
to do it.
> Sure would be nice if all you had to type was a.nonzero().T, though... ;-P
No, this wouldn't be possible -- the output of the nonzero method is a
tuple, not an array. Perhaps this is why it's not _that_ obvious ;)
-- Ed
More information about the NumPy-Discussion
mailing list