PairwiseDistance#
- class torch.nn.PairwiseDistance(p=2.0, eps=1e-06, keepdim=False)[source]#
計算輸入向量之間的成對距離,或輸入矩陣列之間的成對距離。
距離是使用
p-範數計算的,並加上常數eps以避免除以零,如果p為負值,即:其中 是全1向量,
p-範數定義如下:- 引數
- 形狀
輸入1: 或 ,其中 N = 批次維度,D = 向量維度
輸入2: 或 ,形狀與輸入1相同
輸出: 或 ,具體取決於輸入維度。如果
keepdim為True,則輸出為 或 ,具體取決於輸入維度。
示例
>>> pdist = nn.PairwiseDistance(p=2) >>> input1 = torch.randn(100, 128) >>> input2 = torch.randn(100, 128) >>> output = pdist(input1, input2)