tensorflow API:tf.reduce_sum

来源:互联网 发布:汉仪南宫体简下载 mac 编辑:程序博客网 时间:2024/06/05 14:46

tf.reduce_sum
reduce_sum(
input_tensor,
axis=None,
keep_dims=False,
name=None,
reduction_indices=None
)

Computes the sum of elements across dimensions of a tensor.
计算tensor在各维度上的元素总和
Reduces input_tensor along the dimensions given in axis. Unless keep_dims is true, the rank of the tensor is reduced by 1 for each entry in axis. If keep_dims is true, the reduced dimensions are retained with length 1.
给出axis,然后在该轴上降维,除非keep_dims为true,则维度保持不变。
If axis has no entries, all dimensions are reduced, and a tensor with a single element is returned.
不给axis值,则所有维度进行降维,返回一个标量值

For example:

x = tf.constant([[1, 1, 1], [1, 1, 1]])tf.reduce_sum(x)  # 6tf.reduce_sum(x, 0)  # [2, 2, 2]tf.reduce_sum(x, 1)  # [3, 3]tf.reduce_sum(x, 1, keep_dims=True)  # [[3], [3]]tf.reduce_sum(x, [0, 1])  # 6
原创粉丝点击