由于这个函数参数太多,只记录常用的参数和功能。详情参见对应的官方文档
Format:tf.matmul(a,b,name)
Args:
a:`Tensor` of type `float16`, `float32`, `float64`, `int32`, `complex64`,
b: `Tensor` with same type and rank as `a`.(也就是说a ,b的维度和类型必须一致)
其中还特别提到
The inputs must be matrices (or tensors of rank > 2, representing batches of matrices)输入a ,b必须是矩阵或者维度大于2的tensor
另外
Note: This is matrix product, not element-wise product.
所以这个函数是专门矩阵或者tensor乘法,而不是矩阵元素对应元素相乘。这点要注意
栗子:
import tensorflow as tfa = tf.constant([1, 2, 3, 4, 5, 6], shape=[2, 3])b = tf.constant([7, 8, 9, 10, 11, 12], shape=[3, 2]) c = tf.matmul(a, b)with tf.Session() as sess: print(sess.run([a,b,c]))