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 are the differences between view () and reshape ()

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly introduces what are the differences between view () and reshape (). It has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article.

First, let's talk about the difference between Reshape and view

Similarities: all can change the shape of tensor

Differences:

The .view () method can only change the continuous (contiguous) tensor, otherwise the .contiguous () method needs to be called first; the .reshape () method is not subject to this restriction; if transpose, permute, and so on have been called on the tensor, the tensor will no longer be contiguous in memory.

The tensor returned by the .view () method shares the underlying data (memory, note not a shared memory address) with the original tensor; the .view () method may or may not return the copy of the original tensor, which we do not know.

Second, let's talk about the difference between reshape / view and resize_.

The difference between them is more obvious, the former can not change the total number of data when changing the shape, while the latter can only intercept part of the data when changing the shape, and can also make the size larger by interpolation.

But resize can only make the size less than or equal to the original size, while resize_ can make the size larger than the original size.

In addition, torchvision.transformer.Resize () can be changed in any new size, big or small, but requires that the object be Image.

Thank you for reading this article carefully. I hope the article "what is the difference between view () and reshape ()" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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