pytorch中的squeeze和unsqueeze的用法
1:squeeze
squeeze :对tensor变量进行维度压缩,去除维数为1的维度。
import torch
x=torch.rand(2,3,1)
# x.shape :torch.Size([2, 3, 1])
x.squeeze().shape
#torch.Size([2, 3])
x.squeeze(n):在维度n上,进行维度压缩,如果是1维的就压缩,不是就不压
2:unsqueeze
x.unsqueeze(n) :同理,在第n维上添加一维
https://blog.csdn.net/QLeelq/article/details/122225446