torch.unflatten¶
- torch.unflatten(input, dim, sizes) Tensor ¶
將輸入張量的一個維度擴展為多個維度。
參見
torch.flatten()
這個函式的反向操作。它將多個維度合併為一個維度。- 參數
- 返回值
輸入張量的一個視圖 (View),具有指定的展開維度。
- 範例:
>>> 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])