我有一个a= torch.randn(28, 28, 8)
,我想将尺寸交换(0, 1, 2)
到(2, 0, 1)
。我尝试过b = a.transpose(2, 0, 1)
,但收到此错误:
TypeError: transpose() received an invalid combination of arguments - got
(int, int, int), but expected one of:
* (name dim0, name dim1)
* (int dim0, int dim1)
Run Code Online (Sandbox Code Playgroud)
有什么办法可以一次性全部换掉吗?
我对 PyTorch 完全陌生,我想知道在.moveaxis()
和.movedim()
方法方面是否缺少任何内容。对于相同的参数,输出完全相同。这两种方法都不能被替换吗.permute()
?
参考示例:
import torch
mytensor = torch.randn(3,6,3,1,7,21,4)
t_md = torch.movedim(mytensor, 2, 5)
t_ma = torch.moveaxis(mytensor, 2, 5)
print(t_md.shape, t_ma.shape)
print(torch.allclose(t_md, t_ma))
t_p = torch.permute(mytensor, (0, 1, 3, 4, 5, 2, 6))
print(t_p.shape)
print(torch.allclose(t_md, t_p))
Run Code Online (Sandbox Code Playgroud)