get largest 5 np array 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:]