相关疑难解决方法(0)

如何在 Pytorch 中相互交换 3 个维度?

我有一个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)

有什么办法可以一次性全部换掉吗?

python pytorch

8
推荐指数
1
解决办法
1万
查看次数

PyTorch:.movedim() 与.moveaxis() 与.permute()

我对 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)

python pytorch tensor

4
推荐指数
1
解决办法
2658
查看次数

标签 统计

python ×2

pytorch ×2

tensor ×1