当前位置:网站首页>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
边栏推荐
- 企业级日志分析系统ELK
- Three. JS introductory learning notes 03: perspective projection camera
- Three singleton modes of unity (hungry man, lazy man, monobehavior)
- Syntax of generator function (state machine)
- Three. JS introductory learning notes 10:three JS grid
- LeetCode2_ Add two numbers
- Detailed explanation of unity hot update knowledge points and introduction to common solution principles
- Three. JS introductory learning notes 08:orbitcontrols JS plug-in - mouse control model rotation, zoom in, zoom out, translation, etc
- TCP framework___ Unity
- Apache Doris just "graduated": why should we pay attention to this kind of SQL data warehouse?
猜你喜欢
Three. JS introductory learning notes 08:orbitcontrols JS plug-in - mouse control model rotation, zoom in, zoom out, translation, etc
[wechat applet] Chapter (5): basic API interface of wechat applet
Vertex shader to slice shader procedure, varying variable
Streaming end, server end, player end
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
Getting started with webgl (4)
保证接口数据安全的10种方案
LeetCode3_ Longest substring without duplicate characters
Three. JS introductory learning notes 00: coordinate system, camera (temporarily understood)
The unity vector rotates at a point
随机推荐
Spin animation of Cocos performance optimization
Share the technical details of super signature system construction
Three. JS introductory learning notes 03: perspective projection camera
How to create Apple Developer personal account P8 certificate
Cut ffmpeg as needed, and use emscripten to compile and run
Aerospace Hongtu information won the bid for the database system research and development project of a unit in Urumqi
TS typescript type declaration special declaration field number is handled when the key key
Three. JS introductory learning notes 11:three JS group composite object
Shader_ Animation sequence frame
webgl_ Enter the three-dimensional world (1)
航運船公司人工智能AI產品成熟化標准化規模應用,全球港航人工智能/集裝箱人工智能領軍者CIMC中集飛瞳,打造國際航運智能化標杆
[wechat applet] Chapter (5): basic API interface of wechat applet
山东老博会,2022中国智慧养老展会,智能化养老、适老科技展
The rebound problem of using Scrollview in cocos Creator
Three. JS introductory learning notes 05: external model import -c4d into JSON file for web pages
When opening the system window under UE4 shipping, the problem of crash is attached with the plug-in download address
OpenGL's distinction and understanding of VAO, VBO and EBO
Unity drawing plug-in = = [support the update of the original atlas]
C Alibaba cloud OSS file upload, download and other operations (unity is available)
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