Answers for "how do you get indices of n maximum values in a numpy array?"

0

numpy get index of n largest values

numbers = np.array([1, 3, 2, 4])
n = 2
indices = (-numbers).argsort()[:n]
Posted by: Guest on March-05-2021
0

get index of max value python numpy

Simple
>> b
array([0, 5, 2, 3, 4, 5])

>> np.argmax(b)  # Only the first occurrence is returned.
1
-----------------------------
#More complicated
>> a
array([[10, 11, 12],
       [13, 14, 15]])

>> np.argmax(a)
5

>> np.argmax(a, axis=0)
array([1, 1, 1])

>> np.argmax(a, axis=1)
array([2, 2])
Posted by: Guest on November-23-2021

Code answers related to "how do you get indices of n maximum values in a numpy array?"

Python Answers by Framework

Browse Popular Code Answers by Language