How to get indices of N maximum values in a NumPy array?
To get the indices of the N maximum values in a NumPy array, you can use the `numpy.argsort()` function. Here's a step-by-step guide on how to do it:
1. First, import NumPy:
python
import numpy as np
2. Create your NumPy array. Let's assume you have an array named `data`.
3. Use `numpy.argsort()` to get the indices that would sort the array in ascending order:
python
sorted_indices = np.argsort(data)
4. To get the indices of the N maximum values, you can slice the `sorted_indices` array from the end, taking the last N elements:
python
N = 5 # Change this to the desired number of maximum values
max_indices = sorted_indices[-N:]