180412 tf.cond()与tf.reduce_mean()的使用方法

tf.cond()的用法

  • 代码
import tensorflow as tf    
x=tf.constant(4)      
y=tf.constant(5)   
z = tf.multiply(2, 3)      
result = tf.cond(x < y, lambda: tf.add(x, z), lambda: tf.square(y))      
with tf.Session() as session:      
    print('The result is :\n',result.eval()) 
  • 结果
The result is :
 10

tf.reduce_mean()

a = [1,2,3]
b = tf.reduce_mean(a) # reduce指降维,mean指求平均数
with tf.Session() as sess:
    print(sess.run(b)) #结果为2

180412 tf.cond()与tf.reduce_mean()的使用方法_第1张图片

你可能感兴趣的:(tensorflow)