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

indicesmaxnumpypython

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.

Best Answer

>>> a.argmax(axis=0)

array([1, 1, 0])