tensorflow API _ 1 (control_flow_ops.cond)
该函数用来控制程序执行流,相当于if-else了
import tensorflow as tf
from tensorflow.python.ops import control_flow_ops
a = tf.constant(1)
b = tf.constant(3)
condition = tf.convert_to_tensor(False, dtype='bool')
rtval = control_flow_ops.cond(condition,
lambda: a,
lambda: b)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print sess.run(rtval)
输出为 3