torch.renorm¶
- torch.renorm(input, p, dim, maxnorm, *, out=None) Tensor ¶
返回一個 Tensor,其中
input
沿著維度dim
的每個子 Tensor 都經過正規化,使得子 Tensor 的 p-範數低於值maxnorm
。注意
如果某列的範數低於 maxnorm,則該列保持不變。
- 參數
- 關鍵字參數
out (Tensor, optional) – 輸出 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]])