当前位置:网站首页>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
边栏推荐
- Detailed explanation of Cocos creator 2.4.0 rendering process
- Matlab experience summary
- Streaming end, server end, player end
- Excessive dependence on subsidies, difficult collection of key customers, and how strong is the potential to reach the dream of "the first share of domestic databases"?
- 一大波开源小抄来袭
- 20th anniversary of agile: a failed uprising
- LeetCode2_ Add two numbers
- Postman generate timestamp, future timestamp
- C4D learning notes 3- animation - animation rendering process case
- Async and await
猜你喜欢

Tkinter after how to refresh data and cancel refreshing

Gd32 F3 pin mapping problem SW interface cannot be burned

【微信小程序】Chapter(5):微信小程序基础API接口
![[wechat applet] Chapter (5): basic API interface of wechat applet](/img/63/e819113c7c93e273525bc850892972.png)
[wechat applet] Chapter (5): basic API interface of wechat applet

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

航運船公司人工智能AI產品成熟化標准化規模應用,全球港航人工智能/集裝箱人工智能領軍者CIMC中集飛瞳,打造國際航運智能化標杆

webgl_ Enter the three-dimensional world (2)

Webgl texture

深度之眼(六)——矩阵的逆(附:logistic模型一些想法)

When opening the system window under UE4 shipping, the problem of crash is attached with the plug-in download address
随机推荐
Dotween -- ease function
Vite path alias @ configuration
Three. JS introductory learning notes 11:three JS group composite object
webgl_ Enter the three-dimensional world (2)
hellogolang
Cut ffmpeg as needed, and use emscripten to compile and run
SysOM 案例解析:消失的内存都去哪了 !| 龙蜥技术
[excelexport], Excel to Lua, JSON, XML development tool
Ue4/ue5 multi thread development attachment plug-in download address
VS2005 strange breakpoint is invalid or member variable value cannot be viewed
Whole process analysis of unity3d rendering pipeline
Wireless sensor networks -- ZigBee and 6LoWPAN
Regular expression string
webgl_ Enter the three-dimensional world (1)
Matlab experience summary
Do not use memset to clear floating-point numbers
The "go to definition" in VS2010 does not respond or prompts the solution of "symbol not found"
Xingruige database was shortlisted as the "typical solution for information technology application and innovation in Fujian Province in 2021"
Shader basic UV operations, translation, rotation, scaling
Numpy --- basic learning notes