当前位置:网站首页>深度学习之线性代数
深度学习之线性代数
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))#矩阵*矩阵
边栏推荐
- 【软件逆向-自动化】逆向工具大全
- Encryption algorithm - password security
- Amazon MemoryDB for Redis 和 Amazon ElastiCache for Redis 的内存优化
- Leecode brush questions record sword finger offer 43 The number of occurrences of 1 in integers 1 to n
- Mujoco Jacobi - inverse motion - sensor
- Leecode brush questions record sword finger offer 44 A digit in a sequence of numbers
- Everyone is always talking about EQ, so what is EQ?
- What is a responsive object? How to create a responsive object?
- Testers, how to prepare test data
- DAY THREE
猜你喜欢
509 certificat basé sur Go
AI超清修复出黄家驹眼里的光、LeCun大佬《深度学习》课程生还报告、绝美画作只需一行代码、AI最新论文 | ShowMeAI资讯日报 #07.06
Understand the misunderstanding of programmers: Chinese programmers in the eyes of Western programmers
【软件逆向-自动化】逆向工具大全
Memory optimization of Amazon memorydb for redis and Amazon elasticache for redis
陀螺仪的工作原理
What is AVL tree?
threejs图片变形放大全屏动画js特效
DAY ONE
GPIO简介
随机推荐
【vulnhub】presidential1
dynamic programming
Article management system based on SSM framework
iMeta | 华南农大陈程杰/夏瑞等发布TBtools构造Circos图的简单方法
Leecode brush questions record interview questions 32 - I. print binary tree from top to bottom
【vulnhub】presidential1
Amazon MemoryDB for Redis 和 Amazon ElastiCache for Redis 的内存优化
MIT 6.824 - raft Student Guide
智能运维应用之道,告别企业数字化转型危机
VTK volume rendering program design of 3D scanned volume data
Data analysis course notes (V) common statistical methods, data and spelling, index and composite index
build. How to configure the dependent version number in the gradle file
ZYNQ移植uCOSIII
Advanced learning of MySQL -- basics -- multi table query -- inner join
uniapp实现从本地上传头像并显示,同时将头像转化为base64格式存储在mysql数据库中
沉浸式投影在线下展示中的三大应用特点
Model-Free Prediction
Compilation of kickstart file
【软件逆向-求解flag】内存获取、逆变换操作、线性变换、约束求解
Lombok 同时使⽤ @Data 和 @Builder 的坑,你中招没?