当前位置:网站首页>深度学习之线性代数
深度学习之线性代数
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))#矩阵*矩阵
边栏推荐
- Use type aliases in typescript
- ZYNQ移植uCOSIII
- AI super clear repair resurfaces the light in Huang Jiaju's eyes, Lecun boss's "deep learning" course survival report, beautiful paintings only need one line of code, AI's latest paper | showmeai info
- Data analysis course notes (V) common statistical methods, data and spelling, index and composite index
- St table
- AI超清修复出黄家驹眼里的光、LeCun大佬《深度学习》课程生还报告、绝美画作只需一行代码、AI最新论文 | ShowMeAI资讯日报 #07.06
- PXE server configuration
- Idea automatically imports and deletes package settings
- Matlab learning notes
- Web project com mysql. cj. jdbc. Driver and com mysql. jdbc. Driver differences
猜你喜欢
![[2022 the finest in the whole network] how to test the interface test generally? Process and steps of interface test](/img/8d/b59cf466031f36eb50d4d06aa5fbe4.jpg)
[2022 the finest in the whole network] how to test the interface test generally? Process and steps of interface test

What is a responsive object? How to create a responsive object?

Memory optimization of Amazon memorydb for redis and Amazon elasticache for redis

Imeta | Chen Chengjie / Xia Rui of South China Agricultural University released a simple method of constructing Circos map by tbtools

37頁數字鄉村振興智慧農業整體規劃建設方案

uniapp实现从本地上传头像并显示,同时将头像转化为base64格式存储在mysql数据库中

Geo data mining (III) enrichment analysis of go and KEGG using David database

On February 19, 2021ccf award ceremony will be held, "why in Hengdian?"

GPIO简介

DAY FIVE
随机推荐
Model-Free Control
After leaving a foreign company, I know what respect and compliance are
DAY THREE
What is a responsive object? How to create a responsive object?
[2022 the finest in the whole network] how to test the interface test generally? Process and steps of interface test
2022年PMP项目管理考试敏捷知识点(9)
2022 PMP project management examination agile knowledge points (9)
Leecode brush question record sword finger offer 58 - ii Rotate string left
【JokerのZYNQ7020】AXI_EMC。
DAY TWO
DAY FIVE
[CVPR 2022] semi supervised object detection: dense learning based semi supervised object detection
Quaternion attitude calculation of madgwick
Markov decision process
How to use vector_ How to use vector pointer
[CVPR 2022] target detection sota:dino: Detr with improved detecting anchor boxes for end to end object detection
工程师如何对待开源 --- 一个老工程师的肺腑之言
uniapp实现从本地上传头像并显示,同时将头像转化为base64格式存储在mysql数据库中
Jenkins' user credentials plug-in installation
MIT 6.824 - raft Student Guide