[Numpy-discussion] A newbie question: How to get the "rank" of an 1-d array
CL
anewgene at gmail.com
Mon Mar 27 08:37:04 CST 2006
Hi, group,
I need to get the "rank" of an 1-D array (ie. a vector). Note
that "rank" here is not the value returned from "rank(a_array)". It is
the order of the item in its sorted arrray. For example, I have a python
function called "listrank" to return the "rank" as below:
In [19]: x
Out[19]: array([1, 2, 5, 3, 3, 2])
In [20]: listrank(x)
Out[20]: [6, 4, 1, 2, 2, 4]
Somebody suggested me to use "argsort(argsort(x))". But the problem is
it does not handle ties. See the output:
In [21]: argsort(argsort(x))
Out[21]: array([0, 1, 5, 3, 4, 2])
I am wondering if there is a solution in numpy/numarray/numeric to get
this done nicely.
Thanks.
CL
More information about the Numpy-discussion
mailing list