[Numpy-discussion] obtain indexes of a sort ?

Simon Burton simon at arrowtheory.com
Wed Apr 26 16:41:04 EDT 2006


Is it possible to obtain a permutation (array of indices)
representing the transform that sorts an array ? Is there a numpy way
of doing this ?

I can do it in python as:

a = [ 6, 5, 99, 2 ]
idxs = range(len(a))
z = zip(idxs,a)
def zcmp(u,v):
  if u[1]<=v[1]:
    return -1
  return 1
z.sort( zcmp )
idxs = [u[0] for u in z] # <--- permutation

Simon.

-- 
Simon Burton, B.Sc.
Licensed PO Box 8066
ANU Canberra 2601
Australia
Ph. 61 02 6249 6940
http://arrowtheory.com 




More information about the NumPy-Discussion mailing list