Issue
If I have a torch tensor of shape [2, 12] is it possible to make from it a tensor of shape [3, 2, 4] in such a way that data will be split on chunks along the last dimension? View function does not change the order of data, but here I need change the order, that the new dimension will be the first, and the second dimension would not be changed
Here is example image of how data must be split
[2, 12]
............
............
[3, 2, 4]
....|....|....
....|....|....
torch.split function does exactly what I need in sense of shape, but it outputs not a tensor, but a tuple
Solution
I'm assuming you want to split the 12 sized dimension into the leading 3 and trailing 4 dimensions. You simply need to view and permute dimensions:
X = torch.permute(X.view(2, 3, 4), (1, 0, 2))
Answered By - amiasato
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.