numpy return index value of second largest value argpartition code example Example: np argmin top n # For a 2D array indices = np.argpartition(arr, -N, axis=1)[:, -N:]