Pytorch 如何有效地修改/制作成对距离矩阵?
上面的代码用于计算x(M点)和y(N点)之间的成对距离矩阵(M*N) 当两点之间的距离大于特定值“T”时,我希望生成一个两两距离矩阵,该矩阵有0个元素 在这种情况下,我应该怎么做Pytorch 如何有效地修改/制作成对距离矩阵?,pytorch,tensor,Pytorch,Tensor,上面的代码用于计算x(M点)和y(N点)之间的成对距离矩阵(M*N) 当两点之间的距离大于特定值“T”时,我希望生成一个两两距离矩阵,该矩阵有0个元素 在这种情况下,我应该怎么做 谢谢我想您正在寻找: new_dist=troch.where(dist>T,dist,0.) 我想您正在寻找: new_dist=troch.where(dist>T,dist,0.) 完全正确!非常感谢你!多谢各位 x_norm = (x**2).sum(1).view(-1, 1) if y is
谢谢我想您正在寻找:
new_dist=troch.where(dist>T,dist,0.)
我想您正在寻找:
new_dist=troch.where(dist>T,dist,0.)
完全正确!非常感谢你!多谢各位
x_norm = (x**2).sum(1).view(-1, 1)
if y is not None:
y_norm = (y**2).sum(1).view(1, -1)
else:
y = x
y_norm = x_norm.view(1, -1)
dist = (x_norm + y_norm - 2.0 * torch.mm(x, torch.transpose(y, 0, 1)))
return dist