How to get indices of N maximum values in a NumPy array?
Answers
Answered by
1
Answer:-❤
➡️numpy.where() accepts a condition and 2 optional arrays i.e. returns a bool numpy array boolArr, containing TRUE of each element that is equal to 15, for other elements it contains False i.e. Then it will return a tuple of arrays (one for each axis) containing indices where value was TRUE in given bool numpy array
❤Follow me❤
Answered by
1
★彡 ʜᴇʀᴇ ɪs ʏᴏᴜʀ ᴀɴsᴡᴇʀ 彡★
We can get the indices of N maximum values in a NumPy array using the below code:
import numpy as np
arr = np.array([1, 3, 2, 4, 5])
print(arr.argsort()[-3:][::-1])
ᴇʜsᴀss 彡★
Similar questions
India Languages,
6 months ago
Hindi,
6 months ago
Math,
11 months ago
Chemistry,
11 months ago
Sociology,
1 year ago