首页 > 其他分享 >torch.Tensor.view(*shape)

torch.Tensor.view(*shape)

时间:2022-12-08 22:34:08浏览次数:31  
标签:randn Tensor torch shape size view

image

x = torch.randn(4, 4)
x.size()
y = x.view(16)
y.size()
z = x.view(-1, 8)  # the size -1 is inferred from other dimensions
z.size()

a = torch.randn(1, 2, 3, 4)
a.size()
b = a.transpose(1, 2)  # Swaps 2nd and 3rd dimension
b.size()
c = a.view(1, 3, 2, 4)  # Does not change tensor layout in memory
c.size()
torch.equal(b, c)

标签:randn,Tensor,torch,shape,size,view
From: https://www.cnblogs.com/zjuhaohaoxuexi/p/16967607.html

相关文章