How do I get indices of N maximum values in a NumPy array?
Asked 07 September, 2021
Viewed 2.3K times
  • 51
Votes

NumPy proposes a way to get the index of the maximum value of an array via np.argmax.

I would like a similar thing, but returning the indexes of the N maximum values.

For instance, if I have an array, [1, 3, 2, 4, 5], function(array, n=3) would return the indices [4, 3, 1] which correspond to the elements [5, 4, 3].

20 Answer