1、矩阵点乘
# 计算一个矩阵相乘
import tensorflow as tf
m1 = tf.constant([[1, 2]], dtype=tf.int32) # 定义常量张量大小为 1x2, 类型为 tf.int32
m2 = tf.constant([[1],
[2]]) # 定义常量张量大小为 2x1, 类型 tf.int32
dot_operation = tf.matmul(m1, m2) # tf.matmul函数完成两个张量的点乘操作
with tf.Session() as sess:
result = sess.run(dot_operation) # 执行会话,得到运算的结果
print(result)
结果:
[[5]]