[Numpy-discussion] argsort in descending order

Dan Lenski dlenski@gmail....
Sat Sep 6 01:21:57 CDT 2008

On Fri, 05 Sep 2008 07:02:38 -0700, SimonPalmer wrote:

> another newb question I suspect, but is there a way to instruct argsort
> to sort in descending order or should I just sort and reverse?

Just sort and subtract to get the reverse order.  I can think of two 
reasonable ways to do it with no copying:

from numpy import *
a = rand(100)

# this does NOT make a copy of a, simply indexes it backward, and should 
# be very fast
reverseorder = argsort(a[::-1])

# this way doesn't make a copy either, and probably is a little slower
# since it has to do many subtractions
reverseorder = len(a)-1-argsort(a)


More information about the Numpy-discussion mailing list