首页 > 代码库 > PyTorch学习笔记之Variable
PyTorch学习笔记之Variable
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]
PyTorch学习笔记之Variable
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。