In [1]:
import tensorflow as tf

In [2]:
print(tf.__version__)


1.3.0

Running first tensor graph


In [3]:
x = tf.Variable(3, name='x')
y = tf.Variable(4, name='4')

z = x*x*y+ y + 2

In [4]:
sess = tf.Session()

sess.run(x.initializer)
sess.run(y.initializer)
res = sess.run(z)
print(res)

sess.close()


42

In [7]:
# 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

In [8]:
# 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

In [ ]: