• PyTorch学习笔记之Variable_and_function_cat


    application 1

     1 from torch.autograd import Variable
     2 import torch
     3 b = Variable(torch.FloatTensor([64, 100, 43]))
     4 print(b)
     5 '''
     6 Variable containing:
     7   64
     8  100
     9   43
    10 [torch.FloatTensor of size 3]
    11 '''

    application 2

     1 from torch.autograd import Variable
     2 import torch
     3 
     4 a1 = Variable(torch.randn(64, 100, 43))
     5 # print(a)
     6 a2 = Variable(torch.randn(64, 100, 44))
     7 a3 = Variable(torch.randn(64, 100, 45))
     8 a = [a1, a2, a3]
     9 
    10 # method 1
    11 a = torch.cat((i.data for i in a), 2)
    12 # method 2
    13 a = torch.cat(a, 2)
    14 print(a)
    15 '''
    16 Variable containing:
    17 ( 0 ,.,.) = 
    18  -8.0339e-01 -1.0054e+00 -3.8750e-01  ...  -8.1924e-01 -5.0174e-01  1.2302e+00
    19  -2.4266e+00  3.8993e-01  9.6254e-01  ...  -2.6002e-01  3.8668e-01 -1.0960e+00
    20  -9.8618e-01  1.5732e-01 -7.6385e-01  ...  -9.6085e-01  4.7323e-01  1.0353e+00
    21                  ...                   ⋱                   ...                
    22 (63 ,.,.) =        
    23  -8.9123e-01  8.9774e-01 -1.1528e+00  ...   2.8538e-01 -1.3932e+00 -3.7968e-01
    24   1.0256e+00  2.1746e+00  6.9736e-01  ...   1.2657e+00 -1.0258e+00  5.7128e-01
    25  -1.0966e+00  7.1878e-01  3.5268e-01  ...   3.5731e-01  1.9369e+00 -7.3994e-01
    26 [torch.FloatTensor of size 64x100x132]
    27 '''

     function_cat()

     1 >>> x = torch.randn(2, 3)
     2 >>> x
     3     
     4          0.5983 -0.0341  2.4918
     5          1.5981 -0.5265 -0.8735
     6         [torch.FloatTensor of size 2x3]
     7     
     8 >>> torch.cat((x, x, x), 0)
     9     
    10          0.5983 -0.0341  2.4918
    11          1.5981 -0.5265 -0.8735
    12          0.5983 -0.0341  2.4918
    13          1.5981 -0.5265 -0.8735
    14          0.5983 -0.0341  2.4918
    15          1.5981 -0.5265 -0.8735
    16         [torch.FloatTensor of size 6x3]
    17     
    18 >>> torch.cat((x, x, x), 1)
    19     
    20          0.5983 -0.0341  2.4918  0.5983 -0.0341  2.4918  0.5983 -0.0341  2.4918
    21          1.5981 -0.5265 -0.8735  1.5981 -0.5265 -0.8735  1.5981 -0.5265 -0.8735
    22         [torch.FloatTensor of size 2x9]
  • 相关阅读:
    sublime there are no packages for installation
    linux 安装php扩展mbstring
    生成器表达式和列表推导式
    send()和next()
    迭代器生成器
    装饰器
    函数随笔
    Django进阶
    数据结构与算法入门
    MySQL必会
  • 原文地址:https://www.cnblogs.com/Joyce-song94/p/7224945.html
Copyright © 2020-2023  润新知