Let’s learn how to find the numpy index of the max value in Python. We will use 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. There is an argmax function that helps you find that index.
Argmax function scans the whole array and finds the first instance of the max value. It returns the findex 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.