Hi,
I am not sure why you do the for loop here? And why do you compare each training sample with every test one.
Why not just replace the whole for loop by (x_train - x_test).norm() ? Note that if you want to keep the value for each sample, you can specify the dim on which to compute the norm in the torch.norm 7 function.