Issue
I have a a= torch.randn(28, 28, 8)
and I want to swap dimensions (0, 1, 2)
to (2, 0, 1)
.
I tried b = a.transpose(2, 0, 1)
, but I received this error:
TypeError: transpose() received an invalid combination of arguments - got
(int, int, int), but expected one of:
* (name dim0, name dim1)
* (int dim0, int dim1)
Is there any way that I can swap all at once?
Solution
You can use Pytorch's permute()
function to swap all at once,
>>>a = torch.randn(28, 28, 8)
>>>b = a.permute(2, 0, 1)
>>>b.shape
torch.Size([8, 28, 28])
Answered By - Vigneswaran C
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.