编译环境:Anaconda+Spyder
#Mat1为常量,Mat2为变量,所有变量如果要使用,必须初始化
import tensorflow as tf
Mat1 = tf.constant(100)
Mat2 = tf.Variable(9,name = 'Mat2')
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
print(sess.run(Mat1))
print(sess.run(Mat2))
print(Mat1)
print(Mat2)
输出结果:
runfile('E:/tensorflow/new start/test.py', wdir='E:/tensorflow/new start')
100
9
Tensor("Const_5:0", shape=(), dtype=int32)
<tf.Variable 'Mat2_3:0' shape=() dtype=int32_ref>