Solved by BTNug in post #5 
              
              
                Hi @noUmbrella , then that only needs some additional adjustments: 
import torch
import numpy as np

# This is your additional adjustments
P = [2,2]
m = 1
n = 1
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…