Shortcuts

torch.dist

torch.dist(input, other, p=2) 张量

返回 (input - other) 的 p-范数

inputother 的形状必须 可广播

Parameters
  • 输入 (张量) – 输入张量。

  • 其他 (张量) – 右侧输入张量

  • p (float, 可选) – 要计算的范数

示例:

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