[Numpy-discussion] obtain indexes of a sort ?

Zachary Pincus zpincus at stanford.edu
Wed Apr 26 16:46:05 CDT 2006


a.argsort() or numpy.argsort(a)

Zach


On Apr 26, 2006, at 4:40 PM, Simon Burton wrote:

>
> 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
>
>
> -------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services,  
> security?
> Get stuff done quickly with pre-integrated technology to make your  
> job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache  
> Geronimo
> http://sel.as-us.falkag.net/sel? 
> cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion





More information about the Numpy-discussion mailing list