当 f1 和 f2 返回多个张量时

fn1fn2 这两个函数可以返回多个张量,但它们必须返回完全相同的输出数量和类型。

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)
# tf.cond returns a list of two tensors
# sess.run([res1, res2]) will return [2., 1.]