# [SciPy-User] [SciPy-user] Ranking a list of numbers

mdekauwe mdekauwe@gmail....
Thu Jun 3 12:07:05 CDT 2010

```Hi,

Did you mean

import numpy as np
a = np.array([ 0.012, 0.08, 2, 0.5, 0.010, 0.03])
index = np.argsort(a)[::-1]
b = a[index]

print b
[ 2.     0.5    0.08   0.03   0.012  0.01 ]

Mart

Jose Gomez-Dans wrote:
>
> Hi,
> I've done this with loops, but I am sure there is a much nicer way of
> doing
> it with a couple of index tricks.
> Let's say I've got an array of numbers. I want to convert it into an array
> where each element is the rank of that element in the starting array (by
> rank I mean its position when sorted in decreasing order)
>
> For example, if my original array is
> [ 0.012, 0.08, 2, 0.5, 0.010, 0.03]
> my output array ought to look like this (starting at 1, rather than 0)
> [ 5, 3, 1, 2, 6, 4 ]
> meaning "the first element of the array is the 5th largest, the second is
> the 3rd largest, the third is the largest" and so on.
>
> The ordering can be done with argsort[::-1] (to get the decreasing order),
> but to get the final array, I can only think of clumsy ways of doing
> loops.
>
> Any ideas?
> Thanks!
> J
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>

--
View this message in context: http://old.nabble.com/Ranking-a-list-of-numbers-tp28768184p28770319.html
Sent from the Scipy-User mailing list archive at Nabble.com.

```