使用transpose,只能交换某两个维度
大于2维的tensor的话,也可以想象成二维矩阵的转置操作,可以观察下面的例子得出,之后会画个图说明。
>>> t
= torch
.arange(8).reshape(2,2,2)
>>> t
tensor([[[0, 1],
[2, 3]],
[[4, 5],
[6, 7]]])
>> t
.transpose(0,2)
tensor([[[0, 4],
[2, 6]],
[[1, 5],
[3, 7]]])
>>> t
.transpose(0,1)
tensor([[[0, 1],
[4, 5]],
[[2, 3],
[6, 7]]])
转载请注明原文地址:https://ipadbbs.8miu.com/read-22518.html