tf.reduce_sum(arg1,arg2)
对arg1进行求和,消去维度arg2。
arg1:待处理数据
arg2:
如果为空,那么对数据中所有元素求和;
否则,代表消去的维度。
print(tf.reduce_sum( [[1, 2, 3],[1, 2, 3]] ) )
print(tf.reduce_sum( [[1, 2, 3],[1, 2, 3]],0 ) ) #消去第0维,即对矩阵每一列求和
print(tf.reduce_sum( [[1, 2, 3],[1, 2, 3]],1 ) ) #消去第1维,即对矩阵每一行求和
结果:
tf.Tensor(12, shape=(), dtype=int32)
tf.Tensor([2 4 6], shape=(3,), dtype=int32)
tf.Tensor([6 6], shape=(2,), dtype=int32