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