当前位置:网站首页>Deep learning -- data operation
Deep learning -- data operation
2022-07-01 22:46:00 【lxt1101】
torch.arange(12) Produce a result from 0 Start to 11( Include 11) A vector of ,reshape function , Convert the vector to 3x4 Matrix
import torch
x=torch.arange(12)
x=x.reshape(3,4)
#x=torch.zeros((2,3,4))# Two 2 individual , Three elements 4 A three bit array composed of two-dimensional arrays of columns
The first line of code below is equivalent to the above code .sum() Function is used to sum , Below cat The function user merges the two matrices ,dim be equal to 0 When, it means to merge by line ,dim be equal to 1 When, it means merging by column
x=torch.arange(12,dtype=torch.float32).reshape(3,4)
x.sum()
y=torch.tensor([[2.0,1,4,3],[1,2,3,4],[4,3,2,1]])
torch.cat((x,y),dim=0),torch.cat((x,y),dim=1)#dim=0 Press the line / One dimensional merge ,dim=1 By column / Merge in two dimensions ,dim=2
Here is the output :
x=torch.arange(12,dtype=torch.float32).reshape(3,4)
x.sum()
y=torch.tensor([[2.0,1,4,3],[1,2,3,4],[4,3,2,1]])
torch.cat((x,y),dim=0),torch.cat((x,y),dim=1)#dim=0 Press the line / One dimensional merge ,dim=1 By column / Merge in two dimensions ,dim=2
Judge whether it is equal according to logical operators :
# Judge equality by logical operators
# x=torch.arange(0,8,dtype=torch.float32).reshape(2,2,2)
# y=torch.arange(8,16,dtype=torch.float32).reshape(2,2,2)
# torch.cat((x,y),dim=2)
y==x
Here is the output :
tensor([[False, True, False, True],
[False, False, False, False],
[False, False, False, False]])
Even if the shape of the matrix is different in Python It can also be operated by elements through the broadcast mechanism :
a=torch.arange(3).reshape((3,1))
b=torch.arange(2).reshape((1,2))
a,b
a+b# Even if the shape is different , We can still perform per element operations through the broadcast mechanism , Will copy the matrix as (3,2) matrix
Here is the output :
a=torch.arange(3).reshape((3,1))
b=torch.arange(2).reshape((1,2))
a,b
a+b# Even if the shape is different , We can still perform per element operations through the broadcast mechanism , Will copy the matrix as (3,2) matrix
Between the two matrices, Cao Yong can also calculate the general data operation time :+,-,*,**,/:
x=torch.tensor([1.0,2,4,8])
y=torch.tensor([2,2,2,2])
x+y,x-y,x*y,x**y
Here is the output :
x=torch.tensor([1.0,2,4,8])
y=torch.tensor([2,2,2,2])
x+y,x-y,x*y,x**y
边栏推荐
- 内存导致的电脑游戏中显示hdmi无信号 从而死机的情况
- How to write a performance test plan
- 并发编程系列之FutureTask源码学习笔记
- Measurement of reference loop gain and phase margin
- 删除AWS绑定的信用卡账户
- 13th Blue Bridge Cup group B national tournament
- Mixconv code
- Wechat open platform scanning code login [easy to understand]
- 【QT小作】封装一个简单的线程管理类
- In the past 100 years, only 6 products have been approved, which is the "adjuvant" behind the vaccine competition
猜你喜欢
随机推荐
详解Volatile关键字
MySQL的存储过程
详解LockSupport的使用
Indicator trap: seven KPI mistakes that it leaders are prone to make
104. SAP UI5 表格控件的支持复选(Multi-Select)以及如何用代码一次选中多个表格行项目
【juc学习之路第9天】屏障衍生工具
pytorch训练自己网络后可视化特征图谱的代码
快乐数[环类问题之快慢指针]
[untitled]
Friendly serial assistant tutorial_ How to configure friendly serial port debugging assistant - tutorial on using friendly serial port debugging assistant
How to write a performance test plan
搜狗微信APP逆向(二)so层
Clean up system cache and free memory under Linux
Basic knowledge of ngnix
好友新书发布,祝贺(送福利)
人体姿态估计的热图变成坐标点的两种方案
利用SecureCRTPortable远程连接虚拟机
There is no signal in HDMI in computer games caused by memory, so it crashes
In the past 100 years, only 6 products have been approved, which is the "adjuvant" behind the vaccine competition
twenty million two hundred and twenty thousand seven hundred and one