Tensorflow中的reduce_sum函数
函数定义:
reduce_sum(
input_tensor,
axis=None,
keep_dims=False,
name=None,
reduction_indices=None
)
说明:
reduce_sum() 就是求和,由于求和的对象是tensor,所以是沿着tensor的某些维度求和。函数名中加了reduce是表示求和后会降维,当然可以通过设置参数来保证不降维,但是默认就是要降维的。
参数解释:
1)input_tensor:输入的张量。
2)axis:沿着哪个维度求和。
对于二维的input_tensor张量,0表示按列求和,1表示按行求和,[0, 1]表示先按列求和再按行求和。
3)keep_dims:默认值为Flase,表示默认要降维。若设为True,则不降维。
4)name:名字。
5)reduction_indices:默认值是None,即把input_tensor降到 0维,也就是一个数。
对于2维input_tensor,reduction_indices=0时,按列;reduction_indices=1时,按行。
注意,reduction_indices与axis不能同时设置。
Tensorflow中的reduce_mean函数
tf.reduce_mean 函数用于计算张量tensor沿着指定的数轴(tensor的某一维度)上的的平均值,主要用作降维或者计算tensor(图像)的平均值。
reduce_mean(input_tensor,
axis=None,
keep_dims=False,
name=None,
reduction_indices=None)
第一个参数input_tensor: 输入的待降维的tensor;
第二个参数axis: 指定的轴,如果不指定,则计算所有元素的均值;
第三个参数keep_dims:是否降维度,设置为True,输出的结果保持输入tensor的形状,设置为False,输出结果会降低维度;
第四个参数name: 操作的名称;
第五个参数 reduction_indices:在以前版本中用来指定轴,已弃用;
参考:https://blog.youkuaiyun.com/dcrmg/article/details/79797826
https://www.jianshu.com/p/2d7db8b9cec9