torch.renorm
- torch.renorm(input, p, dim, maxnorm, *, out=None) → Tensor
-
返回一个张量,其中
input
沿维度dim
的每个子张量都被规范化,使得该子张量的 p-范数小于maxnorm
。注意
如果某行的范数小于maxnorm,则该行保持不变
- 参数
- 关键字参数
-
out (Tensor, 可选) – 指定输出张量。
示例:
>>> 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]])