In [9]:
# Import `tensorflow`
import tensorflow as tf
import os
# Initialize two constants
x1 = tf.constant([1,2,3,4])
x2 = tf.constant([5,6,7,8])
# Multiply
result = tf.multiply(x1, x2)
# Print the result
print(result)
# Intialize the Session
sess = tf.Session()
# Print the result
print(sess.run(result))
# Close the session
sess.close()
#Or you can run the session like so:
with tf.Session() as sess:
output = sess.run(result)
print(output)
y1=tf.constant(5)
y2=tf.constant(6)
result=tf.multiply(y1, y2)
sess=tf.Session()
print(sess.run(result))
sess.close()
#or
with tf.Session() as sess:
print (sess.run(result))
#this closes the session automatically
#try this:
with tf.Session() as sess:
output=sess.run(result)
print (output)
print (output)
#you can't run sess.run(result) outside of the with action
In [ ]: