Home > database >  argmax() method from numpy is returning only first maximum, How to find indexes of all maximum?
argmax() method from numpy is returning only first maximum, How to find indexes of all maximum?

Time:08-26

I have below code

import numpy as np
np.argmax(np.array([5,5,4]))

This returns only 0. I was expecting that will return all indices where maximum occur i.e. 0 & 1

Is there any way to achieve this?

CodePudding user response:

You can use numpy.where to find all indexes of the max value of the array.

import numpy as np
a = np.array([5,5,4])
res = np.where(a == a.max())[0]
print(res)
# [0 1]
  • Related