简体   繁体   中英

How to find the index of n largest elements in column vector, Python

Is there a built-in function or a very simple way of finding the index of n largest elements in column vector?

v = [[5]
     [3]
     [1]
     [2]
     [4]]

Find the index of the largest 3 elements?

I count the duplicates more than once, and the output should be a list of the indices of those largest numbers

You could flatten the array and get the indices of the top n

>>> arr.flatten().argsort()[-3:][::-1]
array([0, 4, 1])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM