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
  • 相关阅读:
    Camera HAL3学习
    Android GPU呈现模式分析
    Android O版本自定义日志输出目录
    Android Configstore HAL
    Ubuntu下设置adb path的方法
    Ubuntu使用技巧
    PHP学习笔记
    mysql安装
    在ubuntu中安装Python
    OS X在使用<semaphore.h>时报错
  • 原文地址:https://www.cnblogs.com/DDBD/p/14086872.html
Copyright © 2011-2022 走看看