torch stack example

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

showing results for - "torch stack example"
Tam
23 Feb 2017
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
Noemi
04 Oct 2020
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
Valentine
06 Jul 2016
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