当前位置:网站首页>Pytoch learning (4)
Pytoch learning (4)
2022-07-04 19:49:00 【Master Ma】
1、range and arange
establish 1 D tensor
Here is an example :
z = torch.range(1,10)
print(z,z.shape)
z = torch.arange(1,10)
print(z,z.shape)
torch.range(1,10) and torch.arange(10) All produced a 1 An array of dimensions , The type is <class ‘torch.Tensor’>
The difference between them is
range The resulting length is 10-1+1=10 By 1 To 10 Composed of 1 D tensor , type float
and arange What happened was 10-1=9 from 1-9 Composed of 1 Dimensional tensor , type int
Their outputs are
It should be noted that ,range The first value cannot be defaulted ,arange Sure , Default 0, The output is :tensor([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) torch.Size([10])
# z = torch.range(10)
# print(z,z.shape)
z = torch.arange(10)
print(z,z.shape)
Two 、repeat Copy tensor
z = torch.arange(10)
print(z,z.shape)
z = torch.arange(10).repeat(10,1)
print(z,z.shape)
z = torch.arange(10).repeat(10,2,1)
3、 ... and 、View: Change the tensor shape
View The mechanism fills shapes with data sequentially , Be careful , The amount of data required for a defined shape must = The amount of data that can be provided
such as :[10x10] The tensor of can .view(1,1,10,10) It's fine too .view(5,20) But not .view(10,11) , Once the amount of data is different , The error of invalid data will be reported
Code example
z = torch.arange(10)
print(z,z.shape)
z = torch.arange(10).repeat(10,1)
print(z,z.shape)
z = torch.arange(10).repeat(10,1).view(1,1,10,10)
print(z,z.shape)
z = torch.arange(10).view(1,10).repeat(10,2)
print(z,z.shape)
Four 、Concat and add operation
Concat: Tensor splicing , It expands the dimensions of two tensors ,
add: Add tensor , Tensors are added directly , It doesn't expand dimensions .
In general ,feature maps There are two ways to combine , One is the corresponding addition of elements , abbreviation add, The other is to pile up feature maps , abbreviation concatenate.
hypothesis feature map 1 The dimensions are B1∗ C1 ∗ H1 ∗ W1
feature map 2 The dimensions are B2 ∗ C2 ∗ H2 ∗ W2
1) stay add Under the circumstances , It is the addition of two four-dimensional matrices by elements , Then at this time, we need the two matrix dimensions to be all equal . And the dimension of the matrix remains unchanged after adding .
for example 26 * 26 * 256 and 26 * 26 * 256 Add up , The results are 26 * 26 * 256
2) stay concatenate Under the circumstances , We superimpose the two matrices in a certain dimension , This requires that the dimension of this connection can be different , But it must be equal in other dimensions . After stack , A dimension will increase , Is the addition of a dimension on two matrices . such as , We are Channel This dimension connects two matrices , So the new matrix dimension is B2 ∗ ( C2 + C1 )∗ H2 ∗ W2
for example 26 * 26 * 256 and 26 * 26 * 512 Add up , The result is 26 * 26 * 768
边栏推荐
- abc229 总结(区间最长连续字符 图的联通分量计数)
- Educational codeforces round 22 E. Army Creation
- Actual combat simulation │ JWT login authentication
- 92. (cesium chapter) cesium building layering
- 【毕业季】绿蚁新醅酒,红泥小火炉。晚来天欲雪,能饮一杯无?
- 黑马程序员-软件测试--08阶段2-linux和数据库-23-30-进程端口相关,修改文件权限,端口号信息的获取,程序和进程相关操作,linux命令案例
- JVM系列之对象的创建
- Mysql database basic operation -ddl | dark horse programmer
- BCG 使用之CBCGPProgressDlgCtrl進度條使用
- Educational Codeforces Round 22 E. Army Creation
猜你喜欢
Hough Transform 霍夫变换原理
Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
如何使用Async-Awati异步任务处理代替BackgroundWorker?
勾股数规律(任意三个数能够满足勾股定理需要满足的条件)
Crystal optoelectronics: ar-hud products of Chang'an dark blue sl03 are supplied by the company
记一次 .NET 某工控数据采集平台 线程数 爆高分析
Detailed explanation of the binary processing function threshold() of opencv
Cbcgptabwnd control used by BCG (equivalent to MFC TabControl)
Cbcgpprogressdlg progress bar used by BCG
TCP两次挥手,你见过吗?那四次握手呢?
随机推荐
Specify the character set to output
Kotlin classes and objects
牛客小白月赛7 E Applese的超能力
Explicit random number
在线SQL转Excel(xls/xlsx)工具
更强的 JsonPath 兼容性及性能测试之2022版(Snack3,Fastjson2,jayway.jsonpath)
1009 product of polynomials (25 points) (PAT class a)
QT realizes interface sliding switching effect
SSRS筛选器的IN运算(即包含于)用法
Multi table operation - external connection query
TCP waves twice, have you seen it? What about four handshakes?
牛客小白月赛7 谁是神箭手
西门子HMI下载时提示缺少面板映像解决方案
BCG 使用之新建向导效果
1008 Elevator(20 分)(PAT甲级)
92. (cesium chapter) cesium building layering
C语言-入门-基础-语法-流程控制(七)
Kotlin inheritance
有关架构设计的个人思考(本文后续不断修改更新)
FPGA时序约束分享01_四大步骤简述