TensoFlow实现条件语句

import tensorflow as tf

a = tf.constant(20)
b = tf.constant(10)

result1 = tf.cond(a > b, lambda: a, lambda: b)
result2 = tf.cond(a < b, lambda: a, lambda: b)

# Initialize all the variables (including parameters) randomly.
init_op = tf.initialize_all_variables()
  
sess = tf.InteractiveSession()
# Run the init_op, evaluate the model outputs and print the results:
sess.run(init_op)

print sess.run(a)
print sess.run(b)
print "max value is: %d" % sess.run(result1)
print "min value is: %d" % sess.run(result2)


20
10
max value is: 20
min value is: 10
每日一句
    每一个你不满意的现在,都有一个你没有努力的曾经。