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