Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the function of the squeeze () and unsqueeze () functions in pytorch

Shulou Source: shulou.com Published: 2022-06-02 06:49:49 10月03日 Update

This article introduces what is the function of squeeze () and unsqueeze () in pytorch. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

1. Unsqueeze () function

1. Initialize an a first

It can be seen that the dimension of an is (2d3).

two。 Add a dimension to the second dimension so that its dimension becomes (2jue 1jue 3)

You can see that the dimension of a has changed to (2). Similarly, if you need to add a dimension to the penultimate dimension, use b.unsqueeze (- 2).

Second, the introduction of squeeze () function

1. First of all, we get a tensor (tensor) whose dimension is (1, 2, 3).

It can be seen from the picture that the dimension of c is (1 ~ 2)

two。 Let's use the squeeze () function to remove the first dimension

It can be seen that the dimension has become (2p3)

3. In addition,

You can see that the dimension has not changed, it is still (1) because only the dimension is 1 will be removed.

On the role of squeeze () and unsqueeze () function in pytorch is shared here, I hope the above content can be of some help to you, you can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Dimension function function content more help good interest only guys buddies tensors articles knowledge articles this is one-dimensional two-dimensional figure reference Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Linux Redmi Docker Xiaomi