import tensorflow as tf
print(tf.__version__)
1.3.0
x = tf.Variable(3, name='x')
y = tf.Variable(4, name='4')
z = x*x*y+ y + 2
sess = tf.Session()
sess.run(x.initializer)
sess.run(y.initializer)
res = sess.run(z)
print(res)
sess.close()
42
# another way to write the same run code
with tf.Session() as sess:
x.initializer.run()
y.initializer.run()
res = z.eval()
print(res) #session will close automatically
42
# instead of running initializer everytime, we can add a initialize node in our computation graph
init = tf.global_variables_initializer()
with tf.Session() as sess:
init.run()
print(z.eval())
42