Search code examples
pythonnumpyargmax

Does np.argmax return the first maximal?


Does np.argmax return the index of the first maximal element always?

Let a = np.array([1, 3, -7, ...]) be a 1D-array with several maximal elements, say at indices 10, 20 and 30. Numpy seems to return systematically 10 instead of 20 or 30, but I could not find information about this behavior in the documentation, and I could not find the implementation details in the source code. Does anybody know?


Solution

  • Yes, this is actually explicited in the numpy.argmax documentation:

    Notes

    In case of multiple occurrences of the maximum values, the indices corresponding to the first occurrence are returned.