Solved by albanD in post #2 
              
              
                Hi, 
The following will generate the same Tensor without the loop: 
full_size = (width, height)
w_exp = w.unsqueeze(1).expand(full_size).true_divide(height) - 0.5
h_exp = h.unsqueeze(0).expand(full_size).true_divide(width) - 0.5

tensor = torch.stack((w_exp, h_exp), -1)
tensor = tensor.reshape(width…