Hi, for confirmation, you want the output of N points, which is 3, and you also want to get the point coordinates, am I correct?
import torch
import numpy as np
N = 3

# DEFINE ARRAY
Q = [[1,2,3,4,5],
[5,6,9,2,1],
[2,5,4,3,6],
[3,6,2,5,1]]
Qnp = np.array(Q)
Qten = torch.tensor(Qnp)

# Find the Top-K (aka. N in your case)
out = torch.topk(Qten.flatten(), N)
# get the value and indexes of the desired top-K or N
val, ind = out

# reformat the flatten tensor to your 2d coordinates
def find_coord(ind, imsize=[5,5]):
    row = ind // imsize[1]
    col = ind % imsize[1]
    return row+ 1, col+1 # because you want the array to start from 1 instead of zero

# get the 2d coordinates

all_inds = [find_coord(idx, imsize=Qnp.shape) for idx in ind]
print('All your desired indexes: ', all_inds)
print('All your desired top-{} values: {}'.format(N, val))

Hope it helps, cheers~