“Torch.Stack” Kod odpowiedzi

Torch.stack Przykład

a.size()  # 2, 3, 4
b.size()  # 2, 3
b = torch.unsqueeze(b, dim=2)  # 2, 3, 1
# torch.unsqueeze(b, dim=-1) does the same thing

torch.stack([a, b], dim=2)  # 2, 3, 5
Disturbed Dolphin

Pytorch ściskaj

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.Stack

> torch.stack(
    (t1,t2,t3)
    ,dim=0
)
tensor([[1, 1, 1],
        [2, 2, 2],
        [3, 3, 3]])
Disturbed Dolphin

Odpowiedzi podobne do “Torch.Stack”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu