tf.cond


import tensorflow as tf
x = tf.constant(12)
y = tf.constant(5)
def f1(): return tf.multiply(x, 17)
def f2(): return tf.add(y, 23)
r = tf.cond(tf.less(x, y), f1, f2)

print(r.numpy())

如果 x<y,就执行函数 f1 , 否则 就执行 f2

28
posted @ 2022-08-19 22:51  luoganttcc  阅读(8)  评论(0)    收藏  举报