The squeeze() and unsqueeze() functions in pytorch

The usage of squeeze is mainly to compress the dimensions of the data .

The usage of unsqueeze is mainly to decompress the dimensions of the data .

squeeze

1) a.squeeze() is to delete all the dimensions of a in a that are 1

 

2) squeeze(a) is equivalent to a.squeeze()

3) torch.squeeze(a, N) , if the Nth dimension of a is 1, remove it; if it is not 1, the method will fail

4) a.squeeze(1) has the same effect as above

 

 

unsqueeze

 

1) Similar to the usage of squeeze above, the result is opposite

 

 

Guess you like

Origin blog.csdn.net/zhang2362167998/article/details/129161923