當 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.]