Tutorial by Examples

x = tf.constant(1.) bool = tf.constant(True) res = tf.cond(bool, lambda: tf.add(x, 1.), lambda: tf.add(x, 10.)) # sess.run(res) will give you 2.
The two functions fn1 and fn2 can return multiple tensors, but they have to return the exact same number and types of outputs. x = tf.constant(1.) bool = tf.constant(True) def fn1(): return tf.add(x, 1.), x def fn2(): return tf.add(x, 10.), x res1, res2 = tf.cond(bool, fn1, fn2)...
You can pass parameters to the functions in tf.cond() using lambda and the code is as bellow. x = tf.placeholder(tf.float32) y = tf.placeholder(tf.float32) z = tf.placeholder(tf.float32) def fn1(a, b): return tf.mul(a, b) def fn2(a, b): return tf.add(a, b) pred = tf.placeholder(tf....

Page 1 of 1