当前位置:网站首页>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
边栏推荐
- Spin animation of Cocos performance optimization
- Align individual elements to the right under flex layout
- Shipping companies' AI products are mature, standardized and applied on a large scale. CIMC, the global leader in port and shipping AI / container AI, has built a benchmark for international shipping
- webgl_ Enter the three-dimensional world (1)
- Postman generate timestamp, future timestamp
- 如何在shell中实现 backspace
- The "go to definition" in VS2010 does not respond or prompts the solution of "symbol not found"
- C4D learning notes 3- animation - animation rendering process case
- Use moviepy Editor clips videos and intercepts video clips in batches
- Numpy -- data cleaning
猜你喜欢

Three. JS introductory learning notes 08:orbitcontrols JS plug-in - mouse control model rotation, zoom in, zoom out, translation, etc

numpy---基础学习笔记

Use of SVN

JS array foreach source code parsing
通知Notification使用全解析

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

尤雨溪,来了!

It's different for rich people to buy a house

分步式监控平台zabbix

山东老博会,2022中国智慧养老展会,智能化养老、适老科技展
随机推荐
如何在shell中实现 backspace
Unity3D_ Class fishing project, control the distance between collision walls to adapt to different models
U3D_ Infinite Bessel curve
SPI master RX time out interrupt
LeetCode2_ Add two numbers
Numpy -- epidemic data analysis case
Unity3D_ Class fishing project, bullet rebound effect is achieved
Eye of depth (VII) -- Elementary Transformation of matrix (attachment: explanation of some mathematical models)
Three. JS introductory learning notes 10:three JS grid
Points for attention in porting gd32 F4 series programs to gd32 F3 series
Shipping companies' AI products are mature, standardized and applied on a large scale. CIMC, the global leader in port and shipping AI / container AI, has built a benchmark for international shipping
Shader Language
C Alibaba cloud OSS file upload, download and other operations (unity is available)
A link opens the applet code. After compilation, it is easy to understand
Three. JS introductory learning notes 11:three JS group composite object
Numpy --- basic learning notes
SPI master rx time out中断
hellogolang
Async and await
A JS script can be directly put into the browser to perform operations