[Numpy-discussion] obtain indexes of a sort ?

Sasha ndarray at mac.com
Wed Apr 26 16:45:03 CDT 2006


>>> argsort([ 6, 5, 99, 2 ])
array([3, 1, 0, 2])

On 4/26/06, Simon Burton <simon at arrowtheory.com> 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