torch.renorm#
- torch.renorm(input, p, dim, maxnorm, *, out=None) Tensor#
返回一個張量,其中沿維度
dim的input的每個子張量都被歸一化,使得子張量的 p-範數小於maxnorm值。注意
如果行的範數低於 maxnorm,則該行保持不變。
- 引數
- 關鍵字引數
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]])