Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import tensorflow as tf
x = tf.Variable(3, name="x", dtype=tf.int16)
y = tf.Variable(4, name="y", dtype=tf.int16)
a = tf.constant(5, dtype=tf.int16)
b = tf.constant(10, dtype=tf.int16)
c = tf.constant(15, dtype=tf.int16)
op1 = x*x*y
op2 = a*b*c
f = op1 + op2
init = tf.global_variables_initializer()
# How to evaluate op1, op2 and f efficiently, by asking tensorflow to evaluate
# all of them in one single graph
with tf.Session() as ses:
init.run()
op1_val, op2_val, f_val = ses.run([op1, op2, f])
print("Result from computation of graph f_val is: {}".format(f_val))
# Result from computation of graph f_val is: 786
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment