评价此页

torch.renorm#

torch.renorm(input, p, dim, maxnorm, *, out=None) Tensor#

返回一个张量,其中沿维度 diminput 的子张量进行归一化,使得子张量的 p-范数小于 maxnorm 值。

注意

如果行的范数小于 maxnorm,则该行保持不变。

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

  • p (float) – 范数计算的幂次

  • dim (int) – 用于切分以获取子张量的维度

  • maxnorm (float) – 每个子张量保持在其下的最大范数

关键字参数

out (Tensor, optional) – 输出张量。

示例

>>> x = torch.ones(3, 3)
>>> x[1].fill_(2)
tensor([ 2.,  2.,  2.])
>>> x[2].fill_(3)
tensor([ 3.,  3.,  3.])
>>> x
tensor([[ 1.,  1.,  1.],
        [ 2.,  2.,  2.],
        [ 3.,  3.,  3.]])
>>> torch.renorm(x, 1, 0, 5)
tensor([[ 1.0000,  1.0000,  1.0000],
        [ 1.6667,  1.6667,  1.6667],
        [ 1.6667,  1.6667,  1.6667]])