Fix Python – How to get the index of a maximum element in a NumPy array along one axis

Question

Asked By – Peter Smit

I have a 2 dimensional NumPy array. I know how to get the maximum values over axes:

>>> a = array([[1,2,3],[4,3,1]])
>>> amax(a,axis=0)
array([4, 3, 3])

How can I get the indices of the maximum elements? I would like as output array([1,1,0]) instead.

Now we will see solution for issue: How to get the index of a maximum element in a NumPy array along one axis


Answer

>>> a.argmax(axis=0)

array([1, 1, 0])

This question is answered By – eumiro

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0