squeeze and unsqueeze pytorch code example
Example: what is squeeze function in pytorch?
import torch
t = torch.tensor([[1,17,7,
3,9,10]])
print(t)
>>>tensor([[1,17,7,3,9,10]])
print(torch.squeeze(t))
>>>tensor([ 1, 17, 7, 3, 9, 10])
t = torch.tensor([[[1,17,7,
3,9,10]]])
print(t)
>>>tensor([[[1,17,7,3,9,10]]])
print(torch.squeeze(t))
>>>tensor([ 1, 17, 7, 3, 9, 10])