numpy matrix find the position of the top 5 maximums code example
Example 1: np argmin top n
idx = (-arr).argsort()[:n]
Example 2: np argmin top n
# For a 2D array
indices = np.argpartition(arr, -N, axis=1)[:, -N:]
idx = (-arr).argsort()[:n]
# For a 2D array
indices = np.argpartition(arr, -N, axis=1)[:, -N:]