Search
 
SCRIPT & CODE EXAMPLE
 

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)] """
Comment

PREVIOUS NEXT
Code Example
Python :: Python operator to use for set union 
Python :: pca in python 
Python :: how to convert tensorflow 1.15 model to tflite 
Python :: how to get all values from class in python 
Python :: search in django 
Python :: create a dictionary from index and column pandas 
Python :: zip() python 
Python :: how add a favicon to django 
Python :: // in python 
Python :: python message 
Python :: python reverse dictionary 
Python :: python empty list 
Python :: python pyttsx3 
Python :: Join query flask-sqlalchemy 
Python :: python foreach 2d array 
Python :: ValueError: invalid literal for int() with base 10: ' pandas 
Python :: Sendgrid dynamic templating 
Python :: add item to list python 
Python :: docker remote 
Python :: how to split python string into N numbers equally 
Python :: is login a class in python 
Python :: get array from h5py dataset 
Python :: pandas filter 
Python :: access list index python 
Python :: how to store categorical variables in separate dataframe 
Python :: cross validation sklearn 
Python :: python keyword arguments 
Python :: length of list in python 
Python :: django-multivaluedictkeyerror-error 
Python :: assert python 3 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =