首页 > 其他 > 详细

torch : transpose,transpose_

时间:2020-12-04 19:04:29      阅读:33      评论:0      收藏:0      [点我收藏+]
import torch
import torchvision
import torch.nn as nn
import torch.nn.functional as F


# x = torch.randn(2, 3)
x = torch.randn(2, 3,4)
print(x)
print()

y = torch.transpose(x, 0, 1)
print(y)
print()


y = torch.transpose(x, 2, 1)
print(y)

y.transpose_(2, 1) #In-place version of transpose()
print(y)
D:\ProgramData\Miniconda3\python.exe E:/新脚本主文件夹/训练测试项目/test_torch/TRANSPOSE.py
tensor([[[ 0.0745, -0.1144, -0.4868,  2.2905],
         [-0.0286,  0.6754,  0.4262, -0.8590],
         [ 0.3684, -0.2710,  0.6782, -0.5027]],

        [[ 0.9876,  1.1178,  1.1179,  0.6800],
         [ 0.4692,  0.5668, -0.6782,  0.6920],
         [-0.9431,  1.5257,  0.1621,  1.5187]]])

tensor([[[ 0.0745, -0.1144, -0.4868,  2.2905],
         [ 0.9876,  1.1178,  1.1179,  0.6800]],

        [[-0.0286,  0.6754,  0.4262, -0.8590],
         [ 0.4692,  0.5668, -0.6782,  0.6920]],

        [[ 0.3684, -0.2710,  0.6782, -0.5027],
         [-0.9431,  1.5257,  0.1621,  1.5187]]])

tensor([[[ 0.0745, -0.0286,  0.3684],
         [-0.1144,  0.6754, -0.2710],
         [-0.4868,  0.4262,  0.6782],
         [ 2.2905, -0.8590, -0.5027]],

        [[ 0.9876,  0.4692, -0.9431],
         [ 1.1178,  0.5668,  1.5257],
         [ 1.1179, -0.6782,  0.1621],
         [ 0.6800,  0.6920,  1.5187]]])
tensor([[[ 0.0745, -0.1144, -0.4868,  2.2905],
         [-0.0286,  0.6754,  0.4262, -0.8590],
         [ 0.3684, -0.2710,  0.6782, -0.5027]],

        [[ 0.9876,  1.1178,  1.1179,  0.6800],
         [ 0.4692,  0.5668, -0.6782,  0.6920],
         [-0.9431,  1.5257,  0.1621,  1.5187]]])

Process finished with exit code 0

 

torch : transpose,transpose_

原文:https://www.cnblogs.com/DDBD/p/14086872.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!