Finding the Index of Largest Value in a NumPy Array
Start your free 7-days trial now!
There are two simple ways to find the index of the largest value in a Numpy array.
The first way is to use the
argmax(~) function of the Numpy array:
x = np.array([3,5,2,1])x.argmax()1
Here, 1 is returned because the largest value (i.e. 5) is located at index 1.
The second way is to use the
argmax(~) static function of the Numpy module:
x = np.array([3,5,2,1])np.argmax(x)1