Quantcast
Channel: Get indices of N maximum values in a numpy array without sorting them? - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Get indices of N maximum values in a numpy array without sorting them?

$
0
0

My question is very similar to this one: How to get indices of N maximum values in a numpy array?

But I would like to get the indices in the same order I find them.

Let's take the example marked in that question as the correct solution:

import numpy as nparr = np.array([1, 3, 2, 4, 5])arr.argsort()[-3:][::-1]array([4, 3, 1])

The result I'm looking for instead should be like:

array([1, 3, 4])

Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>