TensorFlow的reduce_sum()函数
2017-05-20 09:24
423 查看
日期:2017.5.20
导师让下周二之前用TensorFlow把MNIST跑通,今天看源码碰到这么一行,发现TensorFlow里面的求和函数和其他语言差别挺大,便记录下来。
在知乎上看到几个回答,挺浅显易懂的,话不多说,先上图
上面是TensorFlow官方文档中的函数解释。
其实在reduce_sum()中,是从维度上去考虑的(感觉这个Matlab中数据的概念比较像)
调用
看到这里,函数名的前缀为什么是
导师让下周二之前用TensorFlow把MNIST跑通,今天看源码碰到这么一行,发现TensorFlow里面的求和函数和其他语言差别挺大,便记录下来。
import tensorflow as tf ... # 交叉熵评估代价 cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1])) ...
在知乎上看到几个回答,挺浅显易懂的,话不多说,先上图
上面是TensorFlow官方文档中的函数解释。
其实在reduce_sum()中,是从维度上去考虑的(感觉这个Matlab中数据的概念比较像)
调用
reduce_sum(arg1, arg2)时,参数
arg1即为要求和的数据,
arg2有两个取值分别为0和1,通常用
reduction_indices=[0]或
reduction_indices=[1]来传递参数。从上图可以看出,当
arg2 = 0时,是纵向对矩阵求和,原来矩阵有几列就得到几个值;相似地,当
arg2 = 1时,是横向对矩阵求和;当省略
arg2参数时,默认对矩阵所有元素进行求和。
看到这里,函数名的前缀为什么是
reduce_其实也就很容易理解了,reduce就是“对矩阵降维”的含义,下划线后面的部分就是降维的方式,在
reduce_sum()中就是按照求和的方式对矩阵降维。那么其他
reduce前缀的函数也举一反三了,比如
reduce_mean()就是按照某个维度求平均值,等等。
相关文章推荐
- [转载]Tensorflow 的reduce_sum()函数的axis,keep_dim这些参数到底是什么意思?
- Tensorflow 函数说明tf.reduce_sum
- TensorFlow基础1:reduce_sum()函数和reduce_mean()函数
- 对tf.reduce_sum tensorflow维度上的操作详解
- tensorflow学习之常用函数总结:tensorflow官方例子中的诸如tf.reduce_mean()这类函数
- tensorflow学习之常用函数总结:tensorflow官方例子中的诸如tf.reduce_mean()这类函数
- tensorflow_api_5:tf.reduce_mean()这类函数
- tensorflow:tf.reduce_mean()和tf.reduce_sum()
- tensorflow 中 reduce_sum 理解
- tensorflow中reduce_sum()在维度上的解释
- tensorflow学习之常用函数总结:tensorflow官方例子中的诸如tf.reduce_mean()这类函数
- Tensorflow的reduce_sum的reduction_indices
- tf.reduce_sum tensorflow维度上的操作
- TensorFlow之函数:reduce_mean() 来自于numpy.mean()
- tensorflow中的常用函数(一): constant, reduce_prod, tf.shape
- [tensorflow] which dimension to reduce in tf.reduce_sum()
- tensorflow学习之常用函数总结:tensorflow.reduce_mean()函数
- tensorflow的tf.reduce_mean()函数的使用方法
- python几个重要的函数(lambda,filter,reduce,map,zip)
- tensorflow下的图片标准化函数per_image_standardization