zoukankan      html  css  js  c++  java
  • torch : transpose,transpose_

    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:ProgramDataMiniconda3python.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
  • 相关阅读:
    MyBatis 缓存机制
    MyBatis 动态SQL
    SpringMVC的简介与使用
    捕获组和前后查找
    正则表达式:( ) 小括号、[ ] 中括号、{ } 大括号的区别
    343.整数拆分
    74. 搜索二维矩阵
    数的划分
    213.打家劫舍||
    整数划分为k份
  • 原文地址:https://www.cnblogs.com/DDBD/p/14086872.html
Copyright © 2011-2022 走看看