一、矩阵对应位置元素相乘:*
所以要求相乘的两个矩阵必须形状相同 。
a = tf.constant([[1,2],[3,4]])
b = tf.constant([[10,20],[30,40]])
c =a *b
with tf.Session() as sess:
print(sess.run(c))
二、矩阵乘法:tf.matmul()
两个矩阵乘法 C = tf.matmul(A,B)
A的形状为m*n, B的形状为n*k, 所以C的形状为m*k.
a = tf.constant([[1,2],[3,4]])
b = tf.constant([[10,20],[30,40]])
d = tf.matmul(a,b)
with tf.Session() as sess:
print(sess.run(d))