如果这是一个幼稚的问题,请原谅我,我的测试代码是这样的:
import torch
from torch.nn.modules.distance import PairwiseDistance
list_1 = [[1., 1.,],[1., 1.]]
list_2 = [[1., 1.,],[2., 1.]]
mtrxA=torch.tensor(list_1)
mtrxB=torch.tensor(list_2)
print "A-B distance :",PairwiseDistance(2).forward(mtrxA, mtrxB)
print "A 'self' distance:",PairwiseDistance(2).forward(mtrxA, mtrxA)
print "B 'self' distance:",PairwiseDistance(2).forward(mtrxB, mtrxB)
结果:
^{pr2}$问题是:
Pythorch如何计算成对距离?是为了计算行向量距离吗?
为什么“自我”距离不是0?
更新
将列表“1”和“列表2”更改为:
list_1 = [[1., 1.,1.,],[1., 1.,1.,]]
list_2 = [[1., 1.,1.,],[2., 1.,1.,]]
结果变成:
A-B distance : tensor([1.7321e-06, 1.0000e+00])
A 'self' distance: tensor([1.7321e-06, 1.7321e-06])
B 'self' distance: tensor([1.7321e-06, 1.7321e-06])
看一下^{} 的文档,Pythorch期望在
D
维中有两个N
向量的二维张量,并计算N
对之间的距离。在为什么“自我”距离不是零-可能是因为floating point precision和{}。在
根据https://github.com/pytorch/pytorch/blob/master/torch/nn/functional.py
相关问题 更多 >
编程相关推荐