import tensorflow as tf sess = tf.Session() x = tf.constant(0) a = sess.run( [tf.cond(tf.equal(tf.count_nonzero(x), 0), lambda: tf.constant(True, name="b"), lambda: tf.constant(False,name="a"))] ) print(a)