From the course: Python Functions for Data Science

Indices of min and max values in NumPy arrays - Python Tutorial

From the course: Python Functions for Data Science

Start my 1-month free trial

Indices of min and max values in NumPy arrays

- [Narrator] When working with NumPy arrays, you may need to locate where the minimum and maximum values lie. In other words, you may need to find the indices of the minimum and maximum values. This is where the argmin and argmax functions that are specific to NumPy arrays come in. For example, let's say that I have a variable named array_random containing a NumPy array of 20 random integers from 1 to 50. To find the index of the minimum value in this NumPy array, I can call the argmin function on array_random. It would look like this. I'll go ahead and run this cell. As you can see, the index of the minimum value is 13. Now to find the index of the maximum value in array_random, I can call the argmax function on array_random. It would look like this. I'll go ahead and run this cell. As you can see, the index of the maximum value is 19. There. Now that you've seen how the argmin and argmax function specific to NumPy arrays work, you can use them to find the indices of the minimum and maximum values in your data.

Contents