当前位置:网站首页>[pytoch foundation] torch.stack() function analysis
[pytoch foundation] torch.stack() function analysis
2022-07-26 20:52:00 【Poor to an annual salary of one million】
1 Function function
Use stack Two messages can be retained :[1. Sequence ] and [2. Tensor matrix ] Information , Belong to Expand and splice Function of ; It can be considered that one matrix is compressed into a matrix according to the time series . It often appears in natural language processing (NLP) Image convolution neural network (CV) in .
Official explanation : Connect the sequence of input tensors along a new dimension . All tensors in the sequence should be of the same shape .
In simple terms : The multiple 2 The tensor of the dimension comes together into a 3 D tensor ; Multiple 3 Dimension makes up a 4 D tensor … And so on , That is, adding new dimensions for stacking .
2 Example
import torch
import numpy as np
# establish 3*3 Matrix ,a、b
a=np.array([[1,2,3],[4,5,6],[7,8,9]])
b=np.array([[10,20,30],[40,50,60],[70,80,90]])
# Transform the matrix into Tensor
a = torch.from_numpy(a)
b = torch.from_numpy(b)
tensor([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]], dtype=torch.int32)
tensor([[10, 20, 30],
[40, 50, 60],
[70, 80, 90]], dtype=torch.int32)
2.1 dim=0
d = torch.stack((a, b), dim=0)
print(d)
print(d.size())
tensor([[[ 1, 2, 3],
[ 4, 5, 6],
[ 7, 8, 9]],
[[10, 20, 30],
[40, 50, 60],
[70, 80, 90]]], dtype=torch.int32)
torch.Size([2, 3, 3])
When dim = 0, Every original matrix has also become a dimension , See a matrix as a whole . There are several matrices , The new dimension is , The matrix is the dimension .
2.2 dim=1
d = torch.stack((a, b), dim=1)
print(d)
print(d.size())
tensor([[[ 1, 2, 3],
[10, 20, 30]],
[[ 4, 5, 6],
[40, 50, 60]],
[[ 7, 8, 9],
[70, 80, 90]]], dtype=torch.int32)
torch.Size([3, 2, 3])
Form the first row of each matrix into a first dimensional matrix , Go down in turn , The... Of each matrix n Line composition No n D matrix .size=(n,i,y)
2.3 dim=2
d = torch.stack((a, b), dim=2)
print(d)
print(d.size())
tensor([[[ 1, 10],
[ 2, 20],
[ 3, 30]],
[[ 4, 40],
[ 5, 50],
[ 6, 60]],
[[ 7, 70],
[ 8, 80],
[ 9, 90]]], dtype=torch.int32)
torch.Size([3, 3, 2])
3 reference
[1]【Pytorch】torch.stack() Use
[2] After reading the second understand torch.stack()
边栏推荐
- [英雄星球七月集训LeetCode解题日报] 第26日 并查集
- It is said that HP / Dell / Microsoft / Amazon are considering transferring some hardware production lines outside the mainland
- Houdini 求中点,点连成线
- When there are many query fields, you can add ordinary query and advanced query
- Gartner发布最新《中国AI初创企业市场指南》,弘玑Cyclone再次被评为代表性企业
- What functions does the medical live broadcast platform need
- 实验5 OSPF综合实验
- Tkinter uses WPF controls
- Marketing and sales document management and workflow solutions
- Fitting the new direction of curriculum standards, ape guidance, creating a characteristic new concept content system
猜你喜欢

Message queue -- the problem introduced: repeated consumption & sequential consumption & distributed transactions

Buu brush inscription 4

QT signal and slot connection (loose coupling)

易基因|宏病毒组测序技术介绍

【微信小程序】零基础学 | 小程序语法

【问题篇】浏览器get请求带token

SSM整合实例

Houdini 笔记2

Leetcode-300 最长递增子序列
![[基础服务] [数据库] ClickHouse的安装和配置](/img/fe/5c24e4c3dc17a6a96985e4fe97024e.png)
[基础服务] [数据库] ClickHouse的安装和配置
随机推荐
LCP 11. Statistics of expected number
Buu brush inscription - WANGDING cup column 2
serializable接口的作用是什么?
美国应用材料公司宣布将以22亿美元现金收购国际电气
81.(cesium之家)cesium修改灰色背景(默认蓝色)
Kotlin - coroutinecontext
Fitting the new direction of curriculum standards, ape guidance, creating a characteristic new concept content system
tkinter使用wpf控件
解决IBGP的水平分割和BGP选路原则
[experiment sharing] CCIE BGP routing black hole experiment]
Robin Lee was "poured cold water" enthusiasm! Baidu allied with Huawei Kirin to release "Honghu" chip
全球最聪明50家公司公布:中国厂商占据近半,华为名列第一
Houdini 求中点,点连成线
arm tz硬件支撑
Correct the classpath of your application so that it contains compatible versions of the classes com
Tinui development history
How to obtain Cu block partition information in HM and draw with MATLAB
Opencv DNN deployment onnx model
美司法部律师团队要求法官拒绝受理华为诉讼
hello 你好吗