当前位置:网站首页>深度学习之线性代数
深度学习之线性代数
2022-07-06 16:54:00 【彭祥.】
这里主要介绍一些张量的计算,如求和,转置等
标量运算
import torch
x=torch.tensor(3.0)
y=torch.tensor(4.0)
print(x*y,x+y,x-y,x**y,x/y)#这种单一元素(标量)可以进行各种四则运算等
print(x.shape)
矩阵转置
import torch
x=torch.arange(20).reshape(5,4)
print(x)
print(x.t())#矩阵转置
B = torch.tensor([[1, 2, 3], [2, 0, 4], [3, 4, 5]])
print(B)
print(B==B.t())#对称矩阵转置后与原矩阵相同
关于python中的赋值,其只是将地址赋给了某个变量,当其改变时,会一同改变,可使用y=x.clone()
来重新生成数据
#降维
import torch
A = torch.arange(12, dtype=torch.float32).reshape(3,4)
A_sum_axis0 = A.sum([1])#0为按列求和,1为按行求和,[0,1]为全部,此时即实现了降维
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维时则丢掉了一个变为一个维度,即丢失行维度,同理,0为丢失第一个,2为第三个
print(A_sum_axis0)
print(A)
keepdims会将维度不降而变成一
累加求和
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))#向量点积
y = torch.ones(4, dtype = torch.float32)
x=torch.arange(12,dtype = torch.float32).reshape(3,4)
print(torch.mv(x,y))#向量*矩阵
B = torch.ones(4, 3)
print(torch.mm(x, B))#矩阵*矩阵
边栏推荐
- 48页数字政府智慧政务一网通办解决方案
- Introduction to GPIO
- 准备好在CI/CD中自动化持续部署了吗?
- JWT signature does not match locally computed signature. JWT validity cannot be asserted and should
- Advanced learning of MySQL -- basics -- multi table query -- inner join
- 37 page overall planning and construction plan for digital Village revitalization of smart agriculture
- Clipboard management tool paste Chinese version
- Geo data mining (III) enrichment analysis of go and KEGG using David database
- Model-Free Prediction
- C语言输入/输出流和文件操作【二】
猜你喜欢
随机推荐
2021 SASE integration strategic roadmap (I)
Hero League | King | cross the line of fire BGM AI score competition sharing
If the college entrance examination goes well, I'm already graying out at the construction site at the moment
Win10 startup error, press F9 to enter how to repair?
Imeta | Chen Chengjie / Xia Rui of South China Agricultural University released a simple method of constructing Circos map by tbtools
AI超清修复出黄家驹眼里的光、LeCun大佬《深度学习》课程生还报告、绝美画作只需一行代码、AI最新论文 | ShowMeAI资讯日报 #07.06
Command line kills window process
集合(泛型 & List & Set & 自定义排序)
Understand the misunderstanding of programmers: Chinese programmers in the eyes of Western programmers
[daily problem insight] prefix and -- count the number of fertile pyramids in the farm
Leecode brushes questions to record interview questions 17.16 massagist
Use mujoco to simulate Cassie robot
JS+SVG爱心扩散动画js特效
【JokerのZYNQ7020】AXI_EMC。
Model-Free Control
Are you ready to automate continuous deployment in ci/cd?
48 page digital government smart government all in one solution
【CVPR 2022】目标检测SOTA:DINO: DETR with Improved DeNoising Anchor Boxes for End-to-End Object Detection
基于GO语言实现的X.509证书
How to use vector_ How to use vector pointer