“Torch.unsqueeze” Kode Jawaban

Pytorch menekan

x = torch.zeros(2, 1, 2, 1, 2)
x.size()
>>> torch.Size([2, 1, 2, 1, 2])

y = torch.squeeze(x) # remove 1
y.size()
>>> torch.Size([2, 2, 2])

y = torch.squeeze(x, 0)
y.size()
>>> torch.Size([2, 1, 2, 1, 2])

y = torch.squeeze(x, 1)
y.size()
>>> torch.Size([2, 2, 1, 2])
Open Ocelot

Torch.unsqueeze

a = torch.randn(4, 4, 4)
>>> torch.unsqueeze(a, 0).size()
torch.Size([1, 4, 4, 4])

>>> torch.unsqueeze(a, 1).size()
torch.Size([4, 1, 4, 4])

>>> torch.unsqueeze(a, 2).size()
torch.Size([4, 4, 1, 4])

>>> torch.unsqueeze(a, 3).size()
torch.Size([4, 4, 4, 1])
Easy Echidna

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya