How do I get indices of N maximum values in a NumPy array?
Newer NumPy versions (1.8 and up) have a function called argpartition for this. To get the indices of the four largest elements, do >>> a = np.array([9, 4, 4, 3, 3, 9, 0, 4, 6, 0]) >>> a array([9, 4, 4, 3, 3, 9, 0, 4, 6, 0]) >>> ind = np.argpartition(a, -4)[-4:] >>> ind … Read more