torch stack

Solutions on MaxInterview for torch stack by the best coders in the world

showing results for - "torch stack"
Kip
07 Mar 2018
1x = torch.zeros(2, 1, 2, 1, 2)
2x.size()
3>>> torch.Size([2, 1, 2, 1, 2])
4
5y = torch.squeeze(x) # remove 1
6y.size()
7>>> torch.Size([2, 2, 2])
8
9y = torch.squeeze(x, 0)
10y.size()
11>>> torch.Size([2, 1, 2, 1, 2])
12
13y = torch.squeeze(x, 1)
14y.size()
15>>> torch.Size([2, 2, 1, 2])
16
Iker
10 Jun 2018
1> torch.stack(
2    (t1,t2,t3)
3    ,dim=0
4)
5tensor([[1, 1, 1],
6        [2, 2, 2],
7        [3, 3, 3]])
8
Martín
31 Jul 2019
1a.size()  # 2, 3, 4
2b.size()  # 2, 3
3b = torch.unsqueeze(b, dim=2)  # 2, 3, 1
4# torch.unsqueeze(b, dim=-1) does the same thing
5
6torch.stack([a, b], dim=2)  # 2, 3, 5
7
Maria José
17 Nov 2019
1>>> a = torch.randn([2, 3, 4])
2>>> b = torch.randn([2, 3, 4])
3>>> torch.stack([a, b]).shape
4torch.Size([2, 2, 3, 4])
5
Crystal
02 Jan 2019
1>>> import torch
2>>> a = torch.randn([2, 3, 4])
3>>> b = torch.randn([2, 3])
4>>> b = b.unsqueeze(dim=2)
5>>> b.shape
6torch.Size([2, 3, 1])
7>>> torch.cat([a, b], dim=2).shape
8torch.Size([2, 3, 5])
9