当前位置:网站首页>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
边栏推荐
- flink sql 命令行 连接 yarn
- Pytorch's code for visualizing feature maps after training its own network
- RestTemplate 远程调用工具类
- spark analyze命令使用及其作用 map join broadcast join 广播join
- Awoo's favorite problem (priority queue)
- linux下清理系统缓存并释放内存
- SAP 智能机器人流程自动化(iRPA)解决方案分享
- Understanding of inverted residuals
- 【juc学习之路第9天】屏障衍生工具
- MySQL view exercise
猜你喜欢
Configure filter
SAP GUI 里的收藏夹事务码管理工具
Dark horse programmer - software testing - stage 06 2-linux and database-01-08 Chapter 1 - description of the content of the Linux operating system stage, description of the basic format and common fo
Kubernetes创建Service访问Pod
快乐数[环类问题之快慢指针]
搜狗微信APP逆向(二)so层
YOLOv5.5 调用本地摄像头
Basic knowledge of ngnix
互联网的智算架构设计
104. SAP UI5 表格控件的支持复选(Multi-Select)以及如何用代码一次选中多个表格行项目
随机推荐
QT 使用FFmpeg4将argb的Qimage转换成YUV422P
#yyds干货盘点# 解决名企真题:扭蛋机
搜狗微信APP逆向(二)so层
【无标题】
Chen Tianqi's machine learning compilation course (free)
从零开始学 MySQL —数据库和数据表操作
Configure filter
[jetcache] how to use jetcache
104. SAP UI5 表格控件的支持复选(Multi-Select)以及如何用代码一次选中多个表格行项目
nn.Parameter】Pytorch特征融合自适应权重设置(可学习权重使用)
MySQL MHA high availability configuration and failover
【c语言】malloc函数详解[通俗易懂]
详解Volatile关键字
Clean up system cache and free memory under Linux
园区全光技术选型-中篇
MySQL中对于索引的理解
Dark horse programmer - software testing - stage 06 2-linux and database-01-08 Chapter 1 - description of the content of the Linux operating system stage, description of the basic format and common fo
cvpr2022 human pose estiamtion
切面条 C语言
【juc学习之路第8天】Condition