Skip to content

Instantly share code, notes, and snippets.

@solaris33
Last active April 20, 2019 15:29
Show Gist options
  • Save solaris33/12dc63036219ca06ae5decf4258073be to your computer and use it in GitHub Desktop.
Save solaris33/12dc63036219ca06ae5decf4258073be to your computer and use it in GitHub Desktop.
import tensorflow as tf
i = tf.constant(1)
j = tf.constant(1)
k = tf.constant(1)
def cond(i, j, k):
return tf.less(i, 10)
def body(i, j, k):
add_op = tf.add(i, 1)
multiply_op = tf.multiply(j, i)
multiply_and_add_op = k * i + j
return [add_op, multiply_op, multiply_and_add_op]
result = tf.while_loop(cond, body, [i, j, k])
with tf.Session() as sess:
loop_result = sess.run(result)
print(loop_result)
print(loop_result[0])
print(loop_result[1])
print(loop_result[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment