yes ,its looks good.
I have update the answer again with “torch.diagonal(cos(u,v),0).unsqueeze(0)”
Can you please try that
I should work now.try not to transform to numpy array as long as possible. try to make operations on torch tensor only.