当前位置:网站首页>【Pytorch】Tensor. Use and understanding of continguous()
【Pytorch】Tensor. Use and understanding of continguous()
2022-04-22 04:54:00 【Family leather Chrysanthemum】
Official document address :https://pytorch.org/docs/stable/generated/torch.Tensor.contiguous.html?highlight=torch%20contiguous#torch.Tensor.contiguous
form :Tensor.contiguous(memory_format=torch.contiguous_format) → Tensor
effect : Returns a continuous memory tensor , It contains the same data as the self tensor . If self tensor It is already the specified memory format , Then this function returns self tensor.
Parameters :memory_format (torch.memory_format, optional) The memory format required for the returned tensor . The default value is :torch.contiguous_format.
understand :
This involves pytorch The relationship between the description and storage of tensors . some tensor operation , Will not change tensor Content itself , Instead, it redefines the correspondence between subscripts and elements . The corresponding relationship between subscript and element is Metadata . For example, there are :
- transpose()
- view()
With transpose() For example , Its function is to tensor Do transpose , This operation will not generate a new tensor. The following code , after transpose After the operation , Changed the b,a And it's changing .
import torch
a = torch.randn(2, 3)
b = a.transpose(0, 1)
print("before modify")
print('a:', a)
print('b:', b)
b[1, 1] = 5
print("end modify")
print('a:', a)
print('b:', b)
The output is as follows :
before modify
a: tensor([[-1.0912, -0.0348, -0.8400],
[-0.2839, 0.0912, -1.3085]])
b: tensor([[-1.0912, -0.2839],
[-0.0348, 0.0912],
[-0.8400, -1.3085]])
end modify
a: tensor([[-1.0912, -0.0348, -0.8400],
[-0.2839, 5.0000, -1.3085]])
b: tensor([[-1.0912, -0.2839],
[-0.0348, 5.0000],
[-0.8400, -1.3085]])
Then at this time , We just think a yes contiguous Of ,b It's not . Of course, we can also use the following functions to view :
print(a.is_contiguous()) # True
print(b.is_contiguous()) # False
So use contiguous() The role of Namely : Break the connection between these two tensors , The new tensor opens up a new memory space in memory .
版权声明
本文为[Family leather Chrysanthemum]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210739161582.html
边栏推荐
- JS Chapter 12
- 10. Libevent receives and processes server messages
- Extraction de la fonction Speech de l'ensemble de données emo - DB
- Go parsing command line parameter flag package
- 2022 a special equipment related management (elevator) retraining question bank and answers
- JSP Hello World Chinese garbled code
- 2022.04.20 Huawei written examination
- JVM——》CMS
- Data segmentation in training set tuning
- KNN, cross validation, grid search
猜你喜欢

2022T电梯修理考试试题及在线模拟考试

2022t elevator repair test questions and online simulation test

vue项目 npm run build 打包项目时为css、js文件加时间戳版本号,防止浏览器缓存

JVM - G1 garbage collector

The role and risk of setsql using lamdbaupdatewrapper

2022年P气瓶充装培训试题及答案

Data segmentation in training set tuning

First knowledge of UI automation (inspect.exe + uiautomation)

Kaggle actual combat 4.1 -- time series prediction problem

2022A特种设备相关管理(电梯)考试题模拟考试题库模拟考试平台操作
随机推荐
PHP quickly raises a value in a two-dimensional array to an array key value, array_ The wonderful use of column
C language simple [stack and queue] (bracket matching problem)
【Selenium】UnitTest测试框架的基本应用
2022 question bank and answers of Shandong Province safety officer C certificate special operation certificate examination
Extraction de la fonction Speech de l'ensemble de données emo - DB
Morphological operation of OpenCV image processing
Inotify Brief
在线预览PDF文件功能实现
JVM——》CMS
2022.04.20华为笔试
style/TextAppearance.Compat.Notification.Info) not found.
Leetcode refers to offer 65 No addition, subtraction, multiplication and division***
Autojs automation script how to develop on the computer, detailed reliable tutorial!!!
14. Buffferevent timeout event processing
The simulation generates random numbers and calculates the birthday of each student
Objectbox usage record
How to realize different values and display different colors in MATLAB
Linked list Chapter 4
Leetcode sword finger offer 17 Print from 1 to maximum n digits
Common commands of labelme