当前位置:网站首页>PyTorch 中的乘法:mul()、multiply()、matmul()、mm()、mv()、dot()
PyTorch 中的乘法:mul()、multiply()、matmul()、mm()、mv()、dot()
2022-07-07 13:49:00 【小瓶盖的猪猪侠】
torch.mul()
函数功能:逐个对 input 和 other 中对应的元素相乘。
本操作支持广播,因此 input 和 other 均可以是张量或者数字
import torch
a = torch.randn((1,2))
b = torch.randn((2,1))
print(a,b)
torch.mul(a,b)

torch.multiply()
torch.mul() 的别称
torch.matmul()
matmul可以进行张量乘法, 输入可以是高维.
torch.dot()
函数功能:计算 input 和 output 的点乘,此函数要求 input 和 output 都必须是一维的张量(其 shape 属性中只有一个值)!并且要求两者元素个数相同!
import torch
x = torch.Tensor([1,2])
y = torch.Tensor([3,4])
z = torch.dot(x,y)
z

torch.mm()
函数功能:实现线性代数中的矩阵乘法(matrix multiplication):(n×m) × (m×p) = (n×p) 。
本函数不允许广播!
import torch
x = torch.randn((3,4))
y = torch.randn((4,5))
z = torch.mm(x,y)
z

torch.mv()
函数功能:实现矩阵和向量(matrix × vector)的乘法,要求 input 的形状为 n×m,output 为 torch.Size([m])的一维 tensor.
import torch
x = torch.randn((3,4))
y = torch.randn(4)
z = torch.mv(x,y)
z
边栏推荐
- Vite path alias @ configuration
- Getting started with webgl (2)
- There are many ways to realize the pause function in JS
- Super simple and fully automated generation super signature system (cloud Xiaoduo minclouds.com cloud service instance), free application in-house test app distribution and hosting platform, maintenan
- 10 schemes to ensure interface data security
- Annexb and avcc are two methods of data segmentation in decoding
- Align individual elements to the right under flex layout
- Use moviepy Editor clips videos and intercepts video clips in batches
- numpy---基础学习笔记
- 尤雨溪,来了!
猜你喜欢

神经网络c语言中的指针是怎么回事

一大波开源小抄来袭

Ue4/ue5 multi thread development attachment plug-in download address

AB package details in unity (super detail, features, packaging, loading, manager)

Eye of depth (VII) -- Elementary Transformation of matrix (attachment: explanation of some mathematical models)

无线传感器网络--ZigBee和6LoWPAN
通知Notification使用全解析

Three. JS introductory learning notes 18: how to export JSON files with Blender

Vertex shader to slice shader procedure, varying variable

numpy--数据清洗
随机推荐
Steps to create P8 certificate and warehousing account
喜讯!科蓝SUNDB数据库与鸿数科技隐私数据保护管理软件完成兼容性适配
Mysql database backup script
How to create Apple Developer personal account P8 certificate
Webgl texture
Gd32 F3 pin mapping problem SW interface cannot be burned
Getting started with webgl (1)
How to build your own super signature system (yunxiaoduo)?
Migration and reprint
Cut ffmpeg as needed, and use emscripten to compile and run
通知Notification使用全解析
分步式监控平台zabbix
L'application à l'échelle de la normalisation mature des produits ai des compagnies maritimes, cimc, leader mondial de l'intelligence artificielle portuaire et maritime / intelligence artificielle des
Unity3D_ Class fishing project, bullet rebound effect is achieved
The download button and debug button in keil are grayed out
Shader Language
Streaming end, server end, player end
leetcode 241. Different ways to add parentheses design priority for operational expressions (medium)
2022山东智慧养老展,适老穿戴设备展,养老展,山东老博会
UE4 exports the picture + text combination diagram through ucanvasrendertarget2d