numpy get index of n largest values
numbers = np.array([1, 3, 2, 4])
n = 2
indices = (-numbers).argsort()[:n]
numpy get index of n largest values
numbers = np.array([1, 3, 2, 4])
n = 2
indices = (-numbers).argsort()[:n]
get n largest values from 2D numpy array matrix
""" for this matrix:
[[ 8, 9, 4],
[10, 5, 18],
[ 5, 6, 6]]
"""
n = 5
rows = mat4.shape[0]
row_col_idxs = [(e//rows, e-(e//rows * rows))
for e in mat4.flatten().argsort()[::-1][:n]]
""" result: [(1, 2), (1, 0), (0, 1), (0, 0), (2, 2)] """
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us