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


發佈了76 篇原創文章 · 獲贊 226 · 訪問量 88萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章