tensorflow中reduce_sum()在维度上的解释
2018-03-09 15:24
465 查看
今天在查tf.reduce_sum()的用法的时候,看到的一个解释。
具体的可以看这个问题底下杨镒铭的回答:https://www.zhihu.com/question/51325408?from=profile_question_card
tf.reduce_sum(tensor,dimension),其中第二个参数是维度。
这个函数表面上看是进行加和操作,实际上在做的事情是在降维。比如这个例子:>>> a = tf.constant([[[1,2,3,4],[2,3,4,5],[3,4,5,6]],[[4,5,6,7],[5,6,7,8],[6,7,8,9]]])
>>> a
<tf.Tensor 'Const_1:0' shape=(2, 3, 4) dtype=int32>
>>> b = tf.reduce_sum(a,0)
>>> b
<tf.Tensor 'Sum_2:0' shape=(3, 4) dtype=int32>
>>> c = tf.reduce_sum(a,1)
>>> c
<tf.Tensor 'Sum_3:0' shape=(2, 4) dtype=int32>
a是一个2*3*4维度的矩阵
reduce_sum(a,0)就是将第零个维度抹去,经过该函数之后,维度变为3*4
reduce_sum(a,1)就是将第一个维度抹去,变为2*4
具体的可以看这个问题底下杨镒铭的回答:https://www.zhihu.com/question/51325408?from=profile_question_card
tf.reduce_sum(tensor,dimension),其中第二个参数是维度。
这个函数表面上看是进行加和操作,实际上在做的事情是在降维。比如这个例子:>>> a = tf.constant([[[1,2,3,4],[2,3,4,5],[3,4,5,6]],[[4,5,6,7],[5,6,7,8],[6,7,8,9]]])
>>> a
<tf.Tensor 'Const_1:0' shape=(2, 3, 4) dtype=int32>
>>> b = tf.reduce_sum(a,0)
>>> b
<tf.Tensor 'Sum_2:0' shape=(3, 4) dtype=int32>
>>> c = tf.reduce_sum(a,1)
>>> c
<tf.Tensor 'Sum_3:0' shape=(2, 4) dtype=int32>
a是一个2*3*4维度的矩阵
reduce_sum(a,0)就是将第零个维度抹去,经过该函数之后,维度变为3*4
reduce_sum(a,1)就是将第一个维度抹去,变为2*4
相关文章推荐
- tf.reduce_sum tensorflow维度上的操作
- 对tf.reduce_sum tensorflow维度上的操作详解
- tensorflow:tf.reduce_mean()和tf.reduce_sum()
- TensorFlow基础1:reduce_sum()函数和reduce_mean()函数
- tensorflow 中 reduce_sum 理解
- TensorFlow的reduce_sum()函数
- [tensorflow] which dimension to reduce in tf.reduce_sum()
- Tensorflow的reduce_sum的reduction_indices
- [转载]Tensorflow 的reduce_sum()函数的axis,keep_dim这些参数到底是什么意思?
- Tensorflow 函数说明tf.reduce_sum
- 【tensorflow】tf.one_hot,tf.reduce_mean,tf.argmax,tf.equal,tf.cast学习
- tf.reduce_sum()
- 如何形象地解释 JavaScript 中 map、foreach、reduce 间的区别?
- TensorFlow学习记录--3.MNIST从低级到高级(从全连接网络到卷积神经网络的解释)
- tensorflow中手写数据集inputdata代码解释
- tensor的维度(轴)—axis的解释
- Spark RDD API具体解释(一) Map和Reduce
- Spark RDD API具体解释(一) Map和Reduce
- TensorFlow - 解释 梯度下降算法(gradient descent)
- tensorflow 维度变化