334 Star 1.5K Fork 863

MindSpore / docs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
TensorSum.md 1.26 KB
一键复制 编辑 原始数据 按行查看 历史
宦晓玲 提交于 2023-07-21 15:21 . modify the md links in 1.6

比较与tf.math.reduce_sum的功能差异

查看源文件

tf.math.reduce_sum

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

更多内容详见tf.math.reduce_sum

mindspore.Tensor.sum

 mindspore.Tensor.sum(self, axis=None, dtype=None, keepdims=False, initial=None)

更多内容详见mindspore.Tensor.sum

使用方式

两接口基本功能相同,都是计算某个维度上Tensor的和。不同点在于,mindspore.Tensor.sum多一个入参initial用于设置起始值。

代码示例

from mindspore import Tensor
import mindspore

a = Tensor([10, -5], mindspore.float32)
print(a.sum()) # 5.0
print(a.sum(initial=2)) # 7.0

import tensorflow as tf
tf.enable_eager_execution()

b = tf.constant([10, -5])
print(tf.math.reduce_sum(b).numpy()) # 5
1
https://gitee.com/mindspore/docs.git
git@gitee.com:mindspore/docs.git
mindspore
docs
docs
r1.6

搜索帮助