相关疑难解决方法(0)

在pytorch中重塑和视图之间有什么区别?

在numpy中,我们ndarray.reshape()用于重塑数组.

我注意到在pytorch中,人们使用torch.view(...)同样的目的,但同时也torch.reshape(...)存在.

所以我想知道他们和我应该使用其中任何一个之间的差异是什么?

pytorch

46
推荐指数
4
解决办法
2万
查看次数

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
查看次数

标签 统计

pytorch ×2

python ×1

tensor ×1