当前位置:网站首页>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
边栏推荐
- Model-Free Control
- Memory optimization of Amazon memorydb for redis and Amazon elasticache for redis
- MIT 6.824 - raft Student Guide
- 2022/2/11 summary
- Cross-entrpy Method
- JS+SVG爱心扩散动画js特效
- Use mujoco to simulate Cassie robot
- How to judge whether an element in an array contains all attribute values of an object
- Basic information of mujoco
- 深度学习之线性代数
猜你喜欢
uniapp中redirectTo和navigateTo的区别
2022年PMP项目管理考试敏捷知识点(9)
准备好在CI/CD中自动化持续部署了吗?
Clipboard management tool paste Chinese version
ldap创建公司组织、人员
如何判断一个数组中的元素包含一个对象的所有属性值
509 certificat basé sur Go
How can computers ensure data security in the quantum era? The United States announced four alternative encryption algorithms
Mujoco second order simple pendulum modeling and control
2022/2/11 summary
随机推荐
JS+SVG爱心扩散动画js特效
Memory optimization of Amazon memorydb for redis and Amazon elasticache for redis
MIT 6.824 - raft Student Guide
Why should a complete knapsack be traversed in sequence? Briefly explain
【YoloV5 6.0|6.1 部署 TensorRT到torchserve】环境搭建|模型转换|engine模型部署(详细的packet文件编写方法)
Advanced learning of MySQL -- basics -- transactions
[CVPR 2022] semi supervised object detection: dense learning based semi supervised object detection
Mujoco Jacobi - inverse motion - sensor
How can computers ensure data security in the quantum era? The United States announced four alternative encryption algorithms
@TableId can‘t more than one in Class: “com.example.CloseContactSearcher.entity.Activity“.
三维扫描体数据的VTK体绘制程序设计
Are you ready to automate continuous deployment in ci/cd?
St table
集合(泛型 & List & Set & 自定义排序)
2022/2/12 summary
Lombok 同时使⽤ @Data 和 @Builder 的坑,你中招没?
陀螺仪的工作原理
Advanced learning of MySQL -- basics -- multi table query -- external connection
2022年PMP项目管理考试敏捷知识点(9)
The difference between redirectto and navigateto in uniapp