Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading