[Numpy-discussion] A question about argmax and argsort

Pierre GM pgmdevlist at gmail.com
Wed Dec 20 17:17:54 CST 2006


On Wednesday 20 December 2006 18:02, Tom Denniston wrote:
> If you want the n largest item i would recommend quicksort 
...
> I don't know of a way to do this in numpy.  I think it would require
> adding a cfunction to numpy.  Perhaps an "argnth" function?
>
> Does anyone else know of an existing mechanism?

Is it really needed when you have argsort ?
>>> x=N.array([1,3,5,2,4])
>>> ax=N.argsort(x)
>>> ax
array([0, 3, 1, 4, 2])
>>> x[ax[0]], x[ax[-1]], x[ax-3]]
1, 5,  3

Or am I once again missing the point entirely ?


More information about the Numpy-discussion mailing list