pytorch中的 tensor.permute() 对矩阵进行转置

import torch
x = torch.randint(1,24, (2,3,4))
print(x)
x = x.permute(2, 0, 1)
print(x)

结果:
前: ([[[15, 23, 21, 14],
    [ 2, 15, 7, 14],
    [21, 8, 8, 22]],

    [[15, 3, 19, 3],
    [14, 11, 5, 16],
    [ 5, 1, 16, 1]]])

后: ([[[15, 2, 21],
    [15, 14, 5]],

   [[23, 15, 8],
    [ 3, 11, 1]],

   [[21, 7, 8],
    [19, 5, 16]],

   [[14, 14, 22],
    [ 3, 16, 1]]])

posted @ 2021-04-26 10:15  id_ning  阅读(892)  评论(0编辑  收藏  举报