捷徑

torch.dist

torch.dist(input, other, p=2) Tensor

傳回 (input - other) 的 p-範數

inputother 的形狀必須是可廣播的

參數
  • input (Tensor) – 輸入張量。

  • other (Tensor) – 右側輸入張量

  • p (float, optional) – 要計算的範數

範例

>>> x = torch.randn(4)
>>> x
tensor([-1.5393, -0.8675,  0.5916,  1.6321])
>>> y = torch.randn(4)
>>> y
tensor([ 0.0967, -1.0511,  0.6295,  0.8360])
>>> torch.dist(x, y, 3.5)
tensor(1.6727)
>>> torch.dist(x, y, 3)
tensor(1.6973)
>>> torch.dist(x, y, 0)
tensor(4.)
>>> torch.dist(x, y, 1)
tensor(2.6537)

文件

取得 PyTorch 的完整開發人員文件

查看文件

教學

取得適用於初學者和進階開發人員的深入教學課程

查看教學

資源

尋找開發資源並獲得您的問題解答

查看資源