Using np.argsort()[::-1] to sort in descending order with same values

1.1k Views Asked by At

For example, I have a numpy array like: a = np.array([0.5, 0.1, 0.5)].

When I use np.argsort(a)[::-1] to sort my array in descending order, it returns:

2, 0, 1

Which is technically correct, as np.argsort(a) would return:

1, 0, 2

and I am just reversing the order.

However, I want the sort to be in the order as the original array, so I would like the return to be:

0, 2, 1

How do I do that? Is there a better function than np.argsort()?

1

There are 1 best solutions below

1
MaryRa On

I would try like this

np.argsort(-1 * a)