Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tensorflow as tf
- x, y = tf.Variable(1, 'x'), tf.Variable(1, 'y')
- cond = tf.placeholder_with_default(False, ())
- # first
- x_inc = tf.assign_add(x, 1)
- y_inc = tf.assign_add(y, 1)
- op = tf.case({cond: lambda: x_inc},
- lambda: y_inc)
- # second
- # op = tf.case({cond: lambda: tf.assign_add(x, 1)},
- # lambda: tf.assign_add(y, 1))
- sess = tf.InteractiveSession()
- sess.run(tf.global_variables_initializer())
- sess.run(op, feed_dict={cond: False})
- sess.run(op, feed_dict={cond: True})
- print(sess.run([x, y])) # => first: [3, 3], second: [2, 2]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement