Interactive sessions are another way to use a session. Go ahead and define one:
In [1]:
import tensorflow as tf
sess = tf.InteractiveSession()
We have a matrix we want to invert:
In [2]:
x = tf.constant([[1., 2.]])
neg_op = tf.negative(x)
Since we're using an interactive session, we can just call the eval()
method on the op.
In [3]:
result = neg_op.eval()
print(result)
That code's a little cleaner when using Jupyter notebooks (like this one).
Don't forget to close the session:
In [4]:
sess.close()