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

Peter Smit picture Peter Smit · Mar 29, 2011 · Viewed 214.8k times · Source

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.

Answer

eumiro picture eumiro · Mar 29, 2011
>>> a.argmax(axis=0)

array([1, 1, 0])