Skip to content

Instantly share code, notes, and snippets.

@diogoaurelio
Last active May 9, 2017 07:21
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/5a0fd9501607ecf5b885b8cbecc95540 to your computer and use it in GitHub Desktop.
Save diogoaurelio/5a0fd9501607ecf5b885b8cbecc95540 to your computer and use it in GitHub Desktop.
import tensorflow as tf
a = tf.constant(1)
b = tf.constant(2)
c = a + b
with tf.Session() as session:
result = session.run(c)
print("Tensorflow supports simple summation with op: 'a + b = {}'".format(result))
# Tensorflow supports simple summation with op: a + b = 3
# Alternatively, since in practice we are just building a graph,
# we can explicitely declare to tensorflow how nodes are connected:
d = tf.add(a, b)
with tf.Session() as session:
result = session.run(d)
print("Tensorflow also supports simple summation via op: 'tf.add(a, b) = {}'".format(result))
# Tensorflow also supports simple summation via op: tf.add(a, b) = 3
# If you are confused by the
# with tf.Session() as session:
# statement, then do not worry, it is just a more concise manner to open and close automatically a session:
session = tf.Session()
result = session.run(d)
print("Run again the same computation graph: 'tf.add(a, b) = {}'".format(result))
# Run again the same computation graph: tf.add(a, b) = 3
session.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment