Skip to content

Instantly share code, notes, and snippets.

@diogoaurelio
Created May 31, 2017 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diogoaurelio/aaeab834caea6759633cb1bde67e86f8 to your computer and use it in GitHub Desktop.
Save diogoaurelio/aaeab834caea6759633cb1bde67e86f8 to your computer and use it in GitHub Desktop.
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