Thanks for the help. Are you sure though that’s the problem? If you look at my comment if I change torch.sqrt(res) into res**(1/2) without modifying res.flatten()[::x.size(0) + 1] = 0.0 everything seems to be working.  Any ideas why?
Also if indeed this



 kirk86:

res.flatten()[::x.size(0) + 1] = 0.0


is the conflicting line which is the appropriate way of modifying it:
should each operation be placed on a separate line?
res = res.flatten()
res[::x.size(0) + 1] = 0.0 --> maybe: temp = res[::x.size(0) + 1], temp= 0.0