快捷方式

torch.unflatten

torch.unflatten(input, dim, sizes) Tensor

將輸入張量的某個維度展開為多個維度。

另請參閱

torch.flatten() 是此函式的逆操作。它將多個維度合併為一個。

引數
  • input (Tensor) – 輸入張量。

  • dim (int) – 要展開的維度,指定為 input.shape 的索引。

  • sizes (Tuple[int]) – 展開後的維度的新形狀。其中一個元素可以是 -1,此時將推斷相應的輸出維度。否則,sizes 的乘積必須等於 input.shape[dim]

返回值

輸入張量的一個檢視,其中指定的維度已被展開。

示例:
>>> torch.unflatten(torch.randn(3, 4, 1), 1, (2, 2)).shape
torch.Size([3, 2, 2, 1])
>>> torch.unflatten(torch.randn(3, 4, 1), 1, (-1, 2)).shape
torch.Size([3, 2, 2, 1])
>>> torch.unflatten(torch.randn(5, 12, 3), -2, (2, 2, 3, 1, 1)).shape
torch.Size([5, 2, 2, 3, 1, 1, 3])

文件

查閱 PyTorch 的全面開發者文件

檢視文件

教程

獲取面向初學者和高階開發者的深度教程

檢視教程

資源

查詢開發資源並獲得問題解答

檢視資源