pytorch squeeze

Solutions on MaxInterview for pytorch squeeze by the best coders in the world

showing results for - "pytorch squeeze"
Andrea
24 Sep 2020
1import torch
2t = torch.tensor([[1,17,7,
3                     3,9,10]])
4print(t)
5>>>tensor([[1,17,7,3,9,10]])
6print(torch.squeeze(t))
7>>>tensor([ 1, 17,  7,  3,  9, 10])
8
9t = torch.tensor([[[1,17,7,
10                     3,9,10]]])
11print(t)
12>>>tensor([[[1,17,7,3,9,10]]])
13print(torch.squeeze(t))
14>>>tensor([ 1, 17,  7,  3,  9, 10])
Matteo
21 Jan 2017
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