Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report