python的matmul_TensorFlow:tf.matmul函数
函数:tf.matmulmatmul(
a,
b,
transpose_a=False,
transpose_b=False,
adjoint_a=False,
adjoint_b=False,
a_is_sparse=False,
b_is_sparse=False,
name=None
)
将矩阵 a 乘以矩阵 b,生成a * b
输入必须在任何转换之后是 rank> = 2 的张量,其中内部 2 维度指定有效的矩阵乘法参数,并且任何其他外部维度匹配.
两个矩阵必须是相同类型.支持的类型有:float16,float32,float64,int32,complex64,complex128.
通过将相应的标志之一设置为 True,矩阵可以被转置或 adjointed(共轭和转置).默认情况下,这些都是 False.
如果一个或两个矩阵包含很多的零,则可以通过将相应的 a_is_sparse 或 b_is_sparse 标志设置为 True 来使用更有效的乘法算法,默认为 false.这个优化仅适用于具有数据类型为bfloat16 或 float32 的纯矩阵(rank 为2的张量).
例如:# 2-D tensor `a`
a = tf.constant([1, 2, 3, 4, 5, 6], shape=[2, 3]) => [[1. 2. 3.]
[4. 5. 6.]]
# 2-D tensor `b`
b = tf.constant([7, 8, 9, 10, 11, 12], shape=[3, 2]) => [[7. 8.]
[9. 10.]
[11. 12.]]
c = tf.matmul(a, b) => [[58 64]
[139 154]]
# 3-D tensor `a`
a = tf.constant(np.arange(1, 13, dtype=np.int32),
shape=[2, 2, 3]) => [[[ 1. 2. 3.]
[ 4. 5. 6.]],
[[ 7. 8. 9.]
[10. 11. 12.]]]
# 3-D tensor `b`
b = tf.constant(np.arange(13, 25, dtype=np.int32),
shape=[2, 3, 2]) => [[[13. 14.]
[15. 16.]
[17. 18.]],
[[19. 20.]
[21. 22.]
[23. 24.]]]
c = tf.matmul(a, b) => [[[ 94 100]
[229 244]],
[[508 532]
[697 730]]]
# Since python >= 3.5 the @ operator is supported (see PEP 465).
# In TensorFlow, it simply calls the `tf.matmul()` function, so the
# following lines are equivalent:
d = a @ b @ [[10.], [11.]]
d = tf.matmul(tf.matmul(a, b), [[10.], [11.]])
参数:
a:类型为 float16,float32,float64,int32,complex64,complex128 和 rank > 1的张量.
b:与 a 具有相同类型和 rank.
transpose_a:如果 True,a 在乘法之前转置.
transpose_b:如果 True,b 在乘法之前转置.
adjoint_a:如果 True,a 在乘法之前共轭和转置.
adjoint_b:如果 True,b 在乘法之前共轭和转置.
a_is_sparse:如果 True,a 被视为稀疏矩阵.
b_is_sparse:如果 True,b 被视为稀疏矩阵.
name:操作名称(可选).
返回:
该函数返回与 a 和 b 具有相同类型的张量,其中每个最内矩阵是 a 和 b 中对应矩阵的乘积,例如,如果所有转置或伴随的属性为 False:output[..., i, j] = sum_k (a[..., i, k] * b[..., k, j]), for all indices i, j
Note:这是矩阵乘积,而不是元素的乘积.
可能引发的异常:
ValueError:如果 transpose_a 和 adjoint_a,或者 transpose_b 和 adjoint_b 都设置为 True.
python的matmul_TensorFlow:tf.matmul函数相关推荐
- tf.matmul函数用法
tf.matmul函数用法 函数:tf.matmul 表示:将矩阵 a 乘以矩阵 b,生成a * b matmul(a,b,transpose_a=False,transpose_b=False,ad ...
- tf.multiply、tf.matmul函数
1.tf.multiply函数 函数原型 tf.multiply(x, y, name=None ) 函数说明 两个张量各自对应的位置元素进行相乘,需要两个张量形状相同. 函数使用 >>& ...
- tf计算矩阵维度_tensorflow tf.matmul() (多维)矩阵相乘(多维矩阵乘法)
@tf_export("matmul") def matmul(a, b, transpose_a=False, transpose_b=False, adjoint_a=Fals ...
- python取中间值的函数_tensorflow实现在函数中用tf.Print输出中间值
tensorflow由于其基于静态图的模式,导致写代码的时候很难调试,除了用官方的调试工具外,最直接的方法就是把中间结果输出出来查看,然而,直接用print函数只能输出tensor变量的形状,而不是数 ...
- 【python】tensorflow框架中的tf.gather_nd()函数对应的 pytorch框架的gather_nd()函数
tf.gather_nd 函数对应的pytorch函数 1. 简单介绍 2. 步入正题 2.1 tensorflow tf.gather_nd() 2.2 pytorch框架手动实现gather_nd ...
- 细分tf.multiply()、tf.matmul()、tf.scalar_mul()函数
tf.multiply() 释义:将两个矩阵中对应元素各自相乘 示例: import tensorflow as tfX = tf.constant([[1, 2, 3], [4, 5 ,6]], d ...
- tf.matmul()研究【Python】
含义 表示矩阵乘法 经典实例 import tensorflow as tf import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' # 创建一个常量 o ...
- python的matmul_关于tf.matmul() 和tf.multiply() 的区别说明
我就废话不多说了,大家还是直接看代码吧~ flyfish # a # [[1, 2, 3], # [4, 5, 6]] a = tf.constant([1, 2, 3, 4, 5, 6], shap ...
- tf.placeholder函数说明
函数形式: tf.placeholder( dtype, shape=None, name=None ) 参数: dtype:数据类型.常用的是tf.float32,tf.fl ...
最新文章
- DateChooser控件发布ASP.NET 2.0新版(我的ASP.NET 2.0控件开发书的第二个阶段项目)[请大家一定注意版本的更新,下载最新版]...
- 'str' object is not callable
- 计算机MCI风险快速筛查系统,轻度认知障碍风险快速筛查工具的测算过程及判别效果分析...
- boost跨平台 c++_跨平台C++整数类型 之一 固定宽度整数(boost和C++11)
- c 结构体的简单封装1
- 学习Spring Boot:(十五)使用Lombok来优雅的编码
- 使用 ConnectionStringBuilder 对象创建精确连接字符串
- 神经网络-GoogleNet的发展,介绍,贡献
- HTML-a标签添加下划线
- Python基础学习九 单元测试
- 微信小程序图标 icon组件
- 安骑士主要功能(云盾服务器安全)
- 大一新生计算机课word知识,大一计算机结业论文
- 交大家简单又好吃的蛋黄酥的做法
- 全新小说安装教程小程序源码
- 二十、调度器、预选策略以及优选函数
- python运维脚本简书_通过python+selenium3实现浏览器刷简书文章阅读量
- 基于python的动物判别系统
- QT6在线安装下载速度慢的解决办法,QT6,QT5.15.1,QT5.15.0及旧版本都支持
- 耐看的《银元时代生活史》
热门文章
- 华南理工大学(计算机技术)往年(?- 2019)专业面试题总结
- 项目管理 | 可行性研究报告怎么写?这5大部分一定要在报告里呈现
- win ce车载系统_巨好用的飞利浦车载充电器
- 量化数值评估,查准率和召回率
- ReactNative入门(一)——环境搭建及第一个RN项目—HelloWorld
- Stealth-Persist混合内存系统中持久应用程序的体系结构支持
- Gridview的HyperLinkField操作
- mysql表新增添加一列
- 2020 C++ priority_queue 最大堆与最小堆介绍
- KBP410-ASEMI开关电源整流器件KBP410