tensorflow的tf.matmul()用法详解

matmul的用法是2个矩阵相乘, 将前面矩阵的每一行分别与后面矩阵的列相乘,作为结果矩阵的行列

import tensorflow as tf
import math
import matplotlib.pyplot as plt
A = [[1,2,3],[0,1,1],[2,0,0]]
B = [[0,1,2,0],[4,3,0,0],[0,1,0,0]]
tf.compat.v1.disable_eager_execution()
sess = tf.compat.v1.InteractiveSession()
print(sess.run(tf.matmul(A,B)))

运行结果:

[[ 8 10  2  0]  
[ 4 4 0 0]
[ 0 2 4 0]]

关注公众号“大模型全栈程序员”回复“小程序”获取1000个小程序打包源码。更多免费资源在http://www.gitweixin.com/?p=2627

发表评论

邮箱地址不会被公开。 必填项已用*标注