torch.dist

torch.dist(x, y, p=2) Tensor

返回 inputother 之差的 p-范数

代码中的 inputother 形状必须是 可广播的

参数
  • input (Tensor) – 需要输入的张量。

  • other (Tensor) – 右操作数张量

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

示例:

>>> 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)
本页目录