Let’s learn how to find the index of the maximum value in a Numpy array using the argmax function.
How to use numpy index of max?
You may need to find the index of the max value in the Numpy array. The argmax function can be used to find the index of the maximum value in a Numpy array.
Argmax function scans the whole array and finds the first instance of the max value. It returns the index of the first value.
import numpy as np my_list = np.array([5, 7, 8, 3, 2, 8]) print(f"This is my array: \n {my_list}") max_value = my_list.argmax() print(f"Index of max value: \n {max_value}")
As you may see, there are two occurrences of 8, but argmax returned the index of the first one.