tf.reduce_mean

import tensorflow as tf
import numpy as np
arr = np.arange(10,dtype=np.float32).reshape([5,2])
arr
array([[ 0.,  1.],
       [ 2.,  3.],
       [ 4.,  5.],
       [ 6.,  7.],
       [ 8.,  9.]], dtype=float32)
avg1 = tf.reduce_mean(arr, axis=0)
avg2 = tf.reduce_mean(arr, axis=1)
avg3 = tf.reduce_mean(arr)
with tf.Session() as sess:
    print('axis=0: ', sess.run(avg1))
    print('axis=1: ', sess.run(avg2))
    print(sess.run(avg3))
axis=0:  [ 4.  5.]
axis=1:  [ 0.5  2.5  4.5  6.5  8.5]
4.5

你可能感兴趣的:(tf.reduce_mean)