捷徑

torch.renorm

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

返回一個 Tensor,其中 input 沿著維度 dim 的每個子 Tensor 都經過正規化,使得子 Tensor 的 p-範數低於值 maxnorm

注意

如果某列的範數低於 maxnorm,則該列保持不變。

參數
  • input (Tensor) – 輸入 Tensor。

  • p (float) – 範數計算的次方。

  • dim (int) – 要切片以獲取子 Tensor 的維度。

  • maxnorm (float) – 每個子 Tensor 要保持低於的最大範數。

關鍵字參數

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]])

文件

存取 PyTorch 的完整開發人員文件

檢視文件

教學

取得適用於初學者和進階開發人員的深入教學課程

檢視教學

資源

尋找開發資源並獲得問題解答

檢視資源