Reputation: 2870
The function numpy.argsort
seems to return sorted 1D-array in increasing order. For example,
import numpy as np
x = np.array([3, 1, 2])
ind = np.argsort(x)
x[ind]
returns array([1, 2, 3])
. However, I've read through its documentation but could not find this information.
Could you please explain how to get it?
Upvotes: 1
Views: 5126
Reputation: 3285
So most sorting algorithms sort in ascending order if nothing else is specified. You can always just reverse the output yourself to get the sorting in descending order
import numpy as np
x = np.array([3, 1, 2])
ascending = np.argsort(x)
descending = ascending[::-1]
For more information on sorting direction of np.argsort
, you can have a look at this post Is it possible to use argsort in descending order?
EDIT: I found a reference to the sort order of numpy here: https://numpy.org/doc/stable/reference/generated/numpy.sort.html#numpy.sort where it is mentioned that sorting is done in lexicographic order by default
Upvotes: 3