1.reduce_xxx這類操作,在官方文檔中,都放在Reduction下
這些操作的本質就是降維,以xxx的手段降維。在所有reduce_xxx系列操作中,都有reduction_indices這個參數,即沿某個方向,使用xxx方法,對input_tensor進行降維。reduction_indices的默認值是None,即把input_tensor降到 0維,也就是一個數。對于2維input_tensor,reduction_indices=0時,按列(0維);reduction_indices=1時,按行(1維)
import numpy as np
import tensorflow as tf
x = np.array([[1.,2.,3.],[4.,5.,6.]])
sess = tf.Session()
mean1 = sess.run(tf.reduce_mean(x))
mean2 = sess.run(tf.reduce_mean(x, 0))
mean3 = sess.run(tf.reduce_mean(x, 1))
print (mean1)
print (mean2)
print (mean3)
sess.close()
結果
3.5
[ 2.5 3.5 4.5]
[ 2. 5.]
mean1=(1+2+3+4+5+6)/ 6
mean2=[(1+4)/2,(2+5)/2,(3+6)/2]
mean3=[(1+2+3)/3,(4+5+6)/3]
