做网站如何做视频,广州网站优化服务,广州注册公司的流程及费用,灯塔seotf.reduce_mean(input_tensor, axisNone, keep_dimsFalse, nameNone, reduction_indicesNone)
作用#xff1a;沿着张量不同的数轴进行计算平均值。 参数#xff1a;input_tensor: 被计算的张量#xff0c;确保为数字类型。 axis: 方向数轴#xff0c;如果没有…tf.reduce_mean(input_tensor, axisNone, keep_dimsFalse, nameNone, reduction_indicesNone)
作用沿着张量不同的数轴进行计算平均值。 参数input_tensor: 被计算的张量确保为数字类型。 axis: 方向数轴如果没有指明默认是所有数轴都减小为1。 keep_dims: 如果定义true, 则保留维数但数量个数为0. name: 操作过程的名称。 reduction_indices: 为了旧函数兼容的数轴。
返回值:降低维数的平均值。
如
import tensorflow as tf
#创建张量
x tf.Variable([[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]]);
#显示
init tf.global_variables_initializer();
with tf.Session() as sess:
sess.run(init);
#tf.reduce_mean(input_tensor, axisNone, keep_dimsFalse, nameNone, reduction_indicesNone)
y tf.reduce_mean(x);
y01 tf.reduce_mean(x, axis0, keep_dimsFalse);
y02 tf.reduce_mean(x, axis0, keep_dimsTrue);
y1 tf.reduce_mean(x, axis1);print(x , x.eval());
print(tf.reduce_mean(x) , y.eval());
print(tf.reduce_mean(x, axis0, keep_dimsFalse) , y01.eval());
print(tf.reduce_mean(x, axis0, keep_dimsTrue) , y02.eval())
print(tf.reduce_mean(x, axis1) , y1.eval()); 输出
(x , array([[ 1., 2., 3.],[ 4., 5., 6.],[ 7., 8., 9.]], dtypefloat32))
(tf.reduce_mean(x) , 5.0)
(tf.reduce_mean(x, axis0, keep_dimsFalse) , array([ 4., 5., 6.], dtypefloat32))
(tf.reduce_mean(x, axis0, keep_dimsTrue) , array([[ 4., 5., 6.]], dtypefloat32))
(tf.reduce_mean(x, axis1) , array([ 2., 5., 8.], dtypefloat32)) 即
tf.reduce_mean(x)表示计算所有元素平均值tf.reduce_mean(x, axis0)表示计算列向量平均值
tf.reduce_mean(x, axis1)表示计算行向量平均值