Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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)] """
 
PREVIOUS NEXT
Tagged: #largest #values #numpy #array #matrix
ADD COMMENT
Topic
Name
1+2 =