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) init = tf.global_variables_initializer() init2 = tf.local_variables_initializer() with tf.Session() as sess: init.run() sess.run(init2) local变量和global变量的初始化
原文:https://www.cnblogs.com/yunshangyue71/p/13611189.html