I am trying to return an array that has the rank of each value in the array. For example, given the array below:
import numpy as np arr1 = np.array([4, 5, 3, 1])
I would like to return an array:
array([2, 3, 1, 0])
Thus, the values ββin the returned array indicate the increasing order of the array (i.e., the value in the returned array indicates which is the largest). Using argsort, I can only indicate how the values ββshould be reordered:
arr1.argsort() array([3, 2, 0, 1])
Let me know if this is unclear.
source share