当前位置:网站首页>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=2Judge 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边栏推荐
猜你喜欢

MySQL MHA high availability configuration and failover

详解JMM

切面条 C语言

Slope compensation

104. SAP UI5 表格控件的支持复选(Multi-Select)以及如何用代码一次选中多个表格行项目

leetcode - 287. 寻找重复数

3DE resources have nothing or nothing wrong

Sonic cloud real machine learning summary 6 - 1.4.1 server and agent deployment

功能测试报告的编写

Intelligent computing architecture design of Internet
随机推荐
小红书Scheme跳转到指定页面
Redis配置与优化
Sonic cloud real machine learning summary 6 - 1.4.1 server and agent deployment
Pytorch sharpening chapter | argmax and argmin functions
友善串口助手使用教程_友善串口调试助手怎么进行配置-友善串口调试助手使用教程…
内存导致的电脑游戏中显示hdmi无信号 从而死机的情况
效率提升 - 鼓捣个性化容器开发环境
性能测试计划怎么编写
MySQL数据库详细学习教程
搜狗微信APP逆向(二)so层
Pytorch's code for visualizing feature maps after training its own network
Wechat open platform scanning code login [easy to understand]
MySQL中对于索引的理解
Chen Tianqi's machine learning compilation course (free)
Appium自动化测试基础 — APPium安装(一)
Mixconv code
Slope compensation
【JetCache】JetCache的使用方法与步骤
pytorch训练自己网络后可视化特征图谱的代码
并发编程系列之FutureTask源码学习笔记