- 函数作用
交换一个tensor的两个维度
- 代码示例
>>> cc=torch.randn((2,3,4))
>>> dd=torch.transpose(cc,1,2)
>>> cc.size()
torch.Size([2, 3, 4])
>>> dd.size()
torch.Size([2, 4, 3])
>>> dd=torch.transpose(cc,0,2)
>>> dd.size()
torch.Size([4, 3, 2])
>>> dd=cc.transpose(1,2,0)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: transpose() takes 2 positional arguments but 3 were given
注意只能有两个相关的交换的位置参数。