Hello, everyone! I have a matrix Q whose size is W×H. For a specified point P in Q whose coordinate is (x,y), I want to get the coordinates of the first N points whose value rank top-N from the range of (x-m, y-n) to (x+m,y+n).  How can I address this problem efficiently using PyTorch.
For instance,
Q =
[1,2,3,4,5;
5,6,9,2,1;
2,5,4,3,6;
3,6,2,5,1;
2,4,8,6,2] and the size of Q is 5×5.
When the coordinate of P is (3,3) and m=n=1 and N=3, the N coordinates I want to get are (2,3), (2,2), and (4,2), whose value are 9, 6, 6, respectively.