当前位置:网站首页>Linear algebra of deep learning
Linear algebra of deep learning
2022-07-07 00:41:00 【Peng Xiang】
Here we mainly introduce the calculation of some tensors , If sum , Transpose, etc
Scalar operation
import torch
x=torch.tensor(3.0)
y=torch.tensor(4.0)
print(x*y,x+y,x-y,x**y,x/y)# This single element ( Scalar ) It can perform all kinds of four operations
print(x.shape)
Matrix transposition
import torch
x=torch.arange(20).reshape(5,4)
print(x)
print(x.t())# Matrix transposition
B = torch.tensor([[1, 2, 3], [2, 0, 4], [3, 4, 5]])
print(B)
print(B==B.t())# The symmetric matrix is the same as the original matrix after transposition
About python Assignment in , It just assigns the address to a variable , When it changes , Will change together , You can use y=x.clone()
To regenerate data
# Dimension reduction
import torch
A = torch.arange(12, dtype=torch.float32).reshape(3,4)
A_sum_axis0 = A.sum([1])#0 To sum by column ,1 To sum by line ,[0,1] For all , At this point, dimensionality reduction is achieved
print(A,A_sum_axis0, A_sum_axis0.shape)
A = torch.arange(24, dtype=torch.float32).reshape(2,3,4)
sum_A = A.sum(1)#3 Dimension time loses a dimension and becomes a dimension , That is, the row dimension is missing , Empathy ,0 For losing the first ,2 For the third
print(A_sum_axis0)
print(A)
keepdims It will turn the dimension into one
Sum by accumulation
import torch
A = torch.arange(12, dtype=torch.float32).reshape(3,4)
A_sum_axis0=A.cumsum(0)
print(A)
print(A_sum_axis0)
import torch
y = torch.ones(4, dtype = torch.float32)
print(y)
print(torch.dot(y,y))# Vector dot product
y = torch.ones(4, dtype = torch.float32)
x=torch.arange(12,dtype = torch.float32).reshape(3,4)
print(torch.mv(x,y))# vector * matrix
B = torch.ones(4, 3)
print(torch.mm(x, B))# matrix * matrix
边栏推荐
- 如何判断一个数组中的元素包含一个对象的所有属性值
- What is a responsive object? How to create a responsive object?
- 深度学习之线性代数
- 智能运维应用之道,告别企业数字化转型危机
- Lombok 同时使⽤ @Data 和 @Builder 的坑,你中招没?
- Mujoco second order simple pendulum modeling and control
- MySQL learning notes (mind map)
- Leecode brush questions record sword finger offer 11 Rotate the minimum number of the array
- 接口(接口相关含义,区别抽象类,接口回调)
- 从外企离开,我才知道什么叫尊重跟合规…
猜你喜欢
2022/2/11 summary
深度学习之线性代数
If the college entrance examination goes well, I'm already graying out at the construction site at the moment
2022年PMP项目管理考试敏捷知识点(9)
一图看懂对程序员的误解:西方程序员眼中的中国程序员
学习使用代码生成美观的接口文档!!!
Liuyongxin report | microbiome data analysis and science communication (7:30 p.m.)
【vulnhub】presidential1
C9高校,博士生一作发Nature!
集合(泛型 & List & Set & 自定义排序)
随机推荐
[CVPR 2022] semi supervised object detection: dense learning based semi supervised object detection
Common shortcuts to idea
智能运维应用之道,告别企业数字化转型危机
[yolov5 6.0 | 6.1 deploy tensorrt to torch serve] environment construction | model transformation | engine model deployment (detailed packet file writing method)
Things like random
"Latex" Introduction to latex mathematical formula "suggestions collection"
Geo data mining (III) enrichment analysis of go and KEGG using David database
js导入excel&导出excel
学习使用代码生成美观的接口文档!!!
一图看懂对程序员的误解:西方程序员眼中的中国程序员
MIT 6.824 - raft Student Guide
Leecode brushes questions and records interview questions 01.02 Determine whether it is character rearrangement for each other
build. How to configure the dependent version number in the gradle file
基于GO语言实现的X.509证书
如何判断一个数组中的元素包含一个对象的所有属性值
uniapp实现从本地上传头像并显示,同时将头像转化为base64格式存储在mysql数据库中
Random类的那些事
A way of writing SQL, update when matching, or insert
37頁數字鄉村振興智慧農業整體規劃建設方案
Interface master v3.9, API low code development tool, build your interface service platform immediately