[Numpy-discussion] Strange behavior for argsort() and take()

Charles R Harris charlesr.harris@gmail....
Wed Jun 18 12:10:40 CDT 2008


On Wed, Jun 18, 2008 at 10:53 AM, Stéfan van der Walt <stefan@sun.ac.za>
wrote:

> 2008/6/18 Anne Archibald <peridot.faceted@gmail.com>:
> > In [7]: x.take(x.argsort())
> > Out[7]: array([ 0. ,  0.1,  0.2,  0.3])
> >
> > If you would like to think of it more mathematically, when you feed
> > np.argsort() an array that represents a permutation of the numbers
> > 0,1,...,n-1, you get back the inverse permutation. When you pass a
> > permutation as the argument to x.take(), you apply the permutation to
> > x. (You can also invert a permutation by feeding it as indices to
> > arange(n)).
> >
> > I have been tempted to write some support functions for manipulating
> > permutations, but I'm not sure how generally useful they would be.
>
> Do we have an easy way of grabbing the elements out of an array that
> correspond to
>
> argmax(x, axis) ?
>
> `take` won't do the job; there `axis` has a different meaning.
>

No. I've been thinking of making such a function for a while, called
argtake, for using the results of argsort. I'd also like it too work with
argmax and such that reduce the rank of the matrices, but that is not quite
the same problem. Adding a keep rank flag to argmax and such would help with
that.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20080618/76fc57f1/attachment.html 


More information about the Numpy-discussion mailing list