当前位置:网站首页>verbose np.matmul/np.dot/np.multiply/tf.matmul/tf.multiply/*
verbose np.matmul/np.dot/np.multiply/tf.matmul/tf.multiply/*
2022-08-09 10:47:00 【Fuzzy Pack】
总结
关于numpy
和tensor
The internal data product of ,There are mainly the following related functions that can be operated.
- 通用函数:
*
numpy
中函数:np.matmul
/np.dot
/np.multiply
tensorflow
中函数:tf.matmul
/tf.multiply
一览表
操作/ 数据 | numpy | tensor |
---|---|---|
* | Multiplies bitwise elementwise,返回array | Multiplies bitwise elementwise,返回tensor |
np.matmul(A,B) | 矩阵相乘操作,返回array | <!!无法操作!!> |
np.dot(A,B) | 点积,<Internal operation meaning unknown> | 点积,<Internal operation meaning unknown> |
np.multiply(A,B) | Multiplies bitwise elementwise,返回array | Multiplies bitwise elementwise,返回tensor |
tf.matmul(A,B) | 矩阵相乘操作,返回tensor | 矩阵相乘操作,返回tensor |
tf.multiply(A,B) | Multiplies bitwise elementwise,返回tensor | Multiplies bitwise elementwise,返回tensor |
- Generic functions can work on two kinds of data(
tensor
/array
)进行Multiplies bitwise elementwise的操作,Returns the corresponding data format(tensor
返回tensor
,array
返回array
) np.matmul
可以对numpy
数据矩阵相乘操作,返回array
,对tensor
Data cannot be manipulated; 特殊np.multiply
Two kinds of data can be used(tensor
/array
)均进行Multiplies bitwise elementwise的操作,Returns the corresponding data format(tensor
返回tensor
,array
返回array
)tf.matmul(x,y)
Two kinds of data can be used(tensor
/array
)矩阵相乘操作,均生成tensor
;tf.multiply
Two kinds of data can be used(tensor
/array
)均进行Multiplies bitwise elementwise的操作,均生成tensor
.
Given experimental data
# numpy数据
x = np.random.randn(2,3,4)*10 # 2, 3, 4
y = np.random.randn(2,4,3)*10 # 2, 4, 3
z = np.random.randn(2,3,4)*10 # 2, 3, 4
# tensorflow数据
x_ = tf.convert_to_tensor(x) # 2, 3, 4
y_ = tf.convert_to_tensor(y) # 2, 4, 3
z_ = tf.convert_to_tensor(z) # 2, 3, 4
通用函数*
1.在tensor
数据中,只能对shape
Equal data manipulation.是等效于tf.mul(x, z)
函数的,也就是Multiplies bitwise elementwise,但是该api
被废弃了,被tf.multiply(x_,z_)
代替.
如下所示的结果
int: x_*z_
out: <tf.Tensor 'mul_4:0' shape=(2, 3, 4) dtype=float64>
如果是x_*y_
会报错,Because the matrix structure is wrong.
2. 在numpy
的数据,只能对shape
Equal data manipulation,is equivalent tonp.multiply(x, z)
函数的,也就是Multiplies bitwise elementwise.
int: (x*z).shape
out: [2,3,4]
int: np.multiply(x,z).shape
out: [2,3,4]
如果是x*y
会报错,Because the matrix structure is wrong.
numpy
中的操作函数
1.np.matmul
可以对numpy
数据矩阵相乘操作,返回array
.
对tensor
The reason the data is not actionable is,tensor
Only after the session is opened is it known what specific internal information is.如下
# 对numpy数据操作
np.matmul(x,y)
array([[[ 135.00353387, 91.52903838, -171.80624465],
[ -48.06257232, 226.70191293, -99.31504134],
[ -13.07481602, -65.88699065, -285.02107715]],
[[-418.64431827, 352.70885364, 386.94553585],
[ 316.96375007, 80.67215049, -130.78989204],
[-207.21033988, 47.25128822, 62.5329744 ]]])
## 对tensor操作,Session not opened,shapeNot clear and inoperable.
np.matmul(x_,y_)
ValueError: matmul: Input operand 0 does not have enough dimensions
(has 0, gufunc core with signature (n?,k),(k,m?)->(n?,m?) requires 1)
2.np.multiply
Two kinds of data can be used(tensor
/array
)均进行Multiplies bitwise elementwise的操作,Returns the corresponding data format(tensor
返回tensor
,array
返回array
)
# 对numpy数据操作
np.multiply(x,z)
array([[[ 13.2853443 , 17.24155086, -34.87846792, 38.32096247],
[-170.15795371, -32.70534678, -5.48962254, 130.43221194],
[ 38.3870938 , 150.13360364, 44.23867107, -74.42425187]],
[[ -91.30385223, -6.00035432, 9.35122873, 21.70442799],
[ 36.825695 , -104.87642619, -55.69509325, 89.90946649],
[ 52.98619734, 21.6885545 , 2.57517183, -2.36556962]]])
#对tensor操作
np.multiply(x_,z_)
<tf.Tensor 'mul_8:0' shape=(2, 3, 4) dtype=float64>
3.np.dot
This is the most amazing operation,The official description means dot product,但是我没咋用过,就不写了,And the value produced is after 3D above,会非常奇怪,Strangely against our usual data changes..In fact, this function conforms to a certain formula,Anyone who wants to know more about it can check it out.
tensorflow
中的操作函数
1.tf.matmul(x,y)
可以对numpy和tensor
两种数据矩阵相乘操作 ,均生成tensor
.
tf.matmul(x,y)
<tf.Tensor 'MatMul_1:0' shape=(2, 3, 3) dtype=float64>
tf.matmul(x_,y_)
<tf.Tensor 'MatMul_4:0' shape=(2, 3, 3) dtype=float64>
2.tf.multiply(x,y)
可以对numpy和tensor
两种数据 Multiplies bitwise elementwise 操作,,均生成tensor
.
tf.multiply(x,z)
<tf.Tensor 'Mul_6:0' shape=(2, 3, 4) dtype=float64>
tf.multiply(x_,z_)
<tf.Tensor 'Mul_7:0' shape=(2, 3, 4) dtype=float64>
边栏推荐
- 情感分析SowNLP词库
- 在webgis中显示矢量化后的风险防控信息
- MySQL和MyEclipse的数据库连接操作
- caffe ---make all编辑出错
- How tall is the B+ tree of the MySQL index?
- The torch. The stack () official explanation, explanation and example
- 机器学习--朴素贝叶斯(Naive Bayes)
- Unix Environment Programming Chapter 15 15.7 Message Queuing
- 按键精灵之输出文本
- tensorflow和numpy对应的版本,报FutureWarning: Passing (type, 1) or ‘1type‘ as a synonym of type is deprecate
猜你喜欢
随机推荐
工作--今天的学习
2022强网杯WP
Multi-merchant mall system function disassembly 26 lectures - platform-side distribution settings
faster-rcnn中的RPN原理
AQS同步组件-ForkJoin、BlockingQueue阻塞队列解析和用例
OpengGL绘制立方体的三种方法
百度云大文件网页直接下载
pytorch widedeep文档
中断系统结构及中断控制
我用开天平台做了一个定时发送天气预报系统【开天aPaaS大作战】
unix环境编程 第十五章 15.5FIFO
相关系数计算,热力图绘制,代码实现
情感分析SowNLP词库
多商户商城系统功能拆解26讲-平台端分销设置
[Original] Usage of @PrePersist and @PreUpdate in JPA
Oracle数据库:for update 和for update nowait的区别
史上最小白之《Word2vec》详解
Oracle数据库常用函数总结
ESIM(Enhanced Sequential Inference Model)- 模型详解
遇到恶意退款不用怕,App 内购买项目的退款通知现已可用