1.创建会话,启动会话
import tensorflow as tf
# 创建一个常量 m1 = tf.constant([[3,3]]) # 创建一个常量 m2 = tf.constant([[2],[3]]) # 矩阵乘法op product = tf.matmul(m1, m2) print(product)
# 定义会话 sess = tf.Session() # 调用sess中的run方法来执行矩阵乘法op result = sess.run(product) print(result) sess.close()
with tf.Session() as sess: # 调用sess中的run方法来执行矩阵乘法op result = sess.run(product) print(result)