obtain indexes of a sort ?
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
argsort([ 6, 5, 99, 2 ]) array([3, 1, 0, 2])
On 4/26/06, Simon Burton <simon@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@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion
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@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion
participants (4)
-
Pierre GM
-
Sasha
-
Simon Burton
-
Zachary Pincus