torch.unflatten#
- torch.unflatten(input, dim, sizes) Tensor#
將輸入張量的某個維度展開為多個維度。
另請參閱
torch.flatten()是此函式的逆操作。它將多個維度合併為一個。- 引數
- 返回
輸入張量的一個檢視,其中指定的維度已被解展。
- 示例:
>>> 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])