当前位置:网站首页>深度学习之线性代数
深度学习之线性代数
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))#矩阵*矩阵
边栏推荐
- How to judge whether an element in an array contains all attribute values of an object
- 接口(接口相关含义,区别抽象类,接口回调)
- GPIO简介
- equals()与hashCode()
- stm32F407-------SPI通信
- QT tutorial: creating the first QT program
- 从外企离开,我才知道什么叫尊重跟合规…
- 37 pages Digital Village revitalization intelligent agriculture Comprehensive Planning and Construction Scheme
- 【软件逆向-自动化】逆向工具大全
- 基於GO語言實現的X.509證書
猜你喜欢
If the college entrance examination goes well, I'm already graying out at the construction site at the moment
Mujoco finite state machine and trajectory tracking
The way of intelligent operation and maintenance application, bid farewell to the crisis of enterprise digital transformation
【软件逆向-求解flag】内存获取、逆变换操作、线性变换、约束求解
2022 PMP project management examination agile knowledge points (9)
Geo data mining (III) enrichment analysis of go and KEGG using David database
Racher integrates LDAP to realize unified account login
一图看懂对程序员的误解:西方程序员眼中的中国程序员
Mujoco Jacobi - inverse motion - sensor
准备好在CI/CD中自动化持续部署了吗?
随机推荐
What can the interactive slide screen demonstration bring to the enterprise exhibition hall
PXE server configuration
以机房B级建设标准满足等保2.0三级要求 | 混合云基础设施
DAY SIX
After leaving a foreign company, I know what respect and compliance are
Idea automatically imports and deletes package settings
uniapp实现从本地上传头像并显示,同时将头像转化为base64格式存储在mysql数据库中
Leecode brush question record sword finger offer 56 - ii Number of occurrences of numbers in the array II
Jenkins' user credentials plug-in installation
Advanced learning of MySQL -- basics -- multi table query -- self join
Model-Free Control
ZYNQ移植uCOSIII
接口(接口相关含义,区别抽象类,接口回调)
QT tutorial: creating the first QT program
Interesting wine culture
js导入excel&导出excel
Markov decision process
@TableId can‘t more than one in Class: “com.example.CloseContactSearcher.entity.Activity“.
Google, Baidu and Yahoo are general search engines developed by Chinese companies_ Baidu search engine URL
GEO数据挖掘(三)使用DAVID数据库进行GO、KEGG富集分析