Computer Science, asked by Anonymous, 11 months ago

How to get indices of N maximum values in a NumPy array?

Answers

Answered by Anonymous
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 EHSASS
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