view
、squeeze
、unsqueeze
、transpose
、t
、permute
、expand
、repeat
import torch
a = torch.rand(4, 1, 28, 28)
a.view(4, 28*28)
a.unsqueeze(0).shape
a.unsqueeze(-1).shape
b = torch.rand(32)
b = b.unsqueeze(1).unsqueeze(2).unsqueeze(0)
a = torch.rand(4, 32, 14, 14)
b.expand(4, 32, 14, 14).shape
b.expand(-1, 32, -1, -1)
b.repeat(4, 32, 1, 1).shape
a = torch.randn(3, 4)
a.t()
a = torch.rand(4, 3, 32, 32)
a1 = a.transpose(1, 3).contiguous().view(4, 3*32*32).view(4, 32, 32, 3).transpose(1, 3)
a1.shape
torch.all(torch.eq(a, a1))
a.permute(0, 2, 3, 1).shape