Solved by Naruto-Sasuke in post #2 
              
              
                import torch

a = torch.randn(1000, 1)
a_clone = a.clone()
a = a.expand(1000, 100)
dist = torch.zeros(1000, 100)

p = torch.arange(100)
#p = torch.arange(100).view(100, 1)
p_clone = p.clone()
p = p.expand(1000, 100)
#p = p.expand(100, 1000).permute(1, 0)

loss = 1./(0.1*torch.pow((a-p), 2)+ 1e-5)

f…