torch中的几种乘法。torch.mm, torch.mul, torch.matmul
一、点乘
点乘都是broadcast的,可以用torch.mul(a, b)实现,也可以直接用*实现。
a = torch.ones(3,4)
a
tensor([[1., 1., 1., 1.],
[1., 1., 1., 1.],
[1., 1., 1., 1.]])b = torch.Tensor([1,2,3]).reshape((3,1))
b
tensor([[1.],
[2.],
[3.]])torch.mul(a, b)
tensor([[1., 1., 1., 1.],
[2., 2., 2., 2.],
[3., 3., 3., 3.]])
1
2
3
4
5
6
7
8
9
10
11
12
13
14
当a, b维度不一致时,会自动填充到相同维度相点乘。
二、矩阵乘
矩阵相乘有torch.mm和torch.matmul两个函数。其中前一个是针对二维矩阵,后一个是高维。当torch.mm用于大于二维时将报错。
a = torch.ones(3,4)
b = torch.ones(4,2)
torch.mm(a, b)
tensor([[4., 4.],
[4., 4.],
[4., 4.]])
1
2
3
4
5
6a = torch.ones(3,4)
b = torch.ones(5,4,2)
torch.matmul(a, b).shape
torch.Size([5, 3, 2])
1
2
3
4a = torch.ones(5,4,2)
b = torch.ones(5,2,3)
torch.matmul(a, b).shape
torch.Size([5, 4, 3])
1
2
3
4a = torch.ones(5,4,2)
b = torch.ones(5,2,3)
torch.matmul(b, a).shape
报错。
torch中的几种乘法。torch.mm, torch.mul, torch.matmul相关推荐
- Python中的几种乘法np.dot,np.multiply,*
使用array时,运算符 * 用于计算数量积(点乘),函数 dot() 用于计算矢量积(叉乘). 使用matrix时,运算符 * 用于计算矢量积,函数multiply() 用于计算数量积. 下面是使用 ...
- Torch中的矩阵相乘分类
矩阵相乘在torch中的几种情况 1.矩阵逐元素(Element-wise)乘法 torch.mul(mat1, other) mat和other可以是标量也可以是任意维度的矩阵,只要满足最终相乘是可 ...
- Torch 中添加自己的 nn Modules:以添加 Dropout、 Triplet Loss 为例
Preface 因为要复现前面阅读的一篇论文:<论文笔记:Deep Relative Distance Learning: Tell the Difference Between Similar ...
- torch中的spmm
系列文章目录 本系列记录自己的代码学习知识 torch.matmul的前后两个矩阵维度不同的小结 torch中的transpose和view的不同 torch中的spmm 系列文章目录 前言 一.to ...
- torch中乘法整理,*torch.mul()torch.mv()torch.mm()torch.dot()@torch.mutmal()
目录 *位置乘 torch.mul():数乘 torch.mv():矩阵向量乘法 torch.mm() 矩阵乘法 torch.dot() 点乘积 @操作 torch.matmul() *位置乘 符号* ...
- torch中的乘法符号(*),torch.mm()和torch.matmul(),torch.mul(), torch.bmm()
前言 torch中常见的一些矩阵乘法和元素乘积,说白了无非就是以下四种,为了避免忘了,做个笔记 乘法符号 * torch.mul() torch.mm torch.matmul torch.dot 1 ...
- (原)torch中微调某层参数
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/6221664.html 参考网址: https://github.com/torch/nn/issues ...
- PyTorch: torch.optim 的6种优化器及优化算法介绍
import torch import torch.nn.functional as F import torch.utils.data as Data import matplotlib.pyplo ...
- torch.mul、matmul、mm、bmm的区别
torch.mul torch.mul(input, value, out=None) 参数 描述 input (Tensor) 输入张量 value (Number) 乘到每个元素的数 out (T ...
最新文章
- Linux远程远程控制程序TeamViewer
- python 生成code128c
- 布隆过滤器、一致性哈希算法总结
- [JavaWeb-MySQL]MySQL服务启动和关闭
- 4.1)深度卷积网络:卷积神经网络基础
- 配置ssl证书_Mysql配置ssl证书
- 【数据库系统】核心知识归纳总结
- 使用asp.net改变图片颜色
- 单例对象会被jvm的gc时回收吗_设计模式专题02-单例五种创建方式
- 你有遇到过最没良心的人吗?
- python画图实战_python实战学习之matplotlib绘图续
- pycharm remote 远程项目 同步 本地_手把手教你Pycharm远程连接服务器端项目进行本地开发调试...
- VUE+JAVA下载文件相关博客
- QQ音乐会员QMC格式批量在线转换为MP3格式
- 6. LaTeX 参考文献的排版与引用
- 【练习】Building a Hypermedia-Driven RESTful Web Service
- 大数据存储1----什么是hdfs!!!
- 163邮箱注册容量多大?外贸一般用什么邮箱,海外邮箱哪个好?
- 安装laravel/Horizon
- 代练通 服务器维护,服务器什么毛病?
热门文章
- 第三,四章 数据库和数据表的(增删改查,重命名等)基本操作
- Highlight(高亮)Gridview控件列
- 有鱼上钩!卖鱼!卖鱼!
- 第13届景驰-埃森哲杯广东工业大学ACM程序设计大赛--K-密码
- Faster-RCNN 训练自己的数据
- 计算机网络学习笔记--网络层知识点整理
- [JavaWeb基础] 012.Struts2 自定义标签使用
- SwiftUI 打开高德地图
- Windows服务器管理(3)——IIS服务器误删了Default Web Site 网站 解决方法
- [转]微服务轮子项目(27) -MySQL 主从复制、主从切换、主主复制