📜  从 2D numpy 数组矩阵中获取 n 个最大值 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:31.949000             🧑  作者: Mango

代码示例1
""" 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)] """