mindspore/docs/api/api_python/ops/mindspore.ops.ReduceSum.rst

33 lines
1.4 KiB
ReStructuredText
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

mindspore.ops.ReduceSum
=========================
.. py:class:: mindspore.ops.ReduceSum(keep_dims=False)
默认情况下输出Tensor各维度上的和以达到对所有维度进行归约的目的。也可以对指定维度进行求和归约。
通过指定 `keep_dims` 参数,来控制输出和输入的维度是否相同。
**参数:**
- **keep_dims** (bool) - 如果为True则保留计算维度长度为1。如果为False则不保留计算维度。默认值False输出结果会降低维度。
**输入:**
- **x** (Tensor[Number]) - ReduceSum的输入任意维度的Tensor秩应小于8。其数据类型为Number。
- **axis** (Union[int, tuple(int), list(int)]) - 指定计算维度。默认值:(),即计算所有元素的和。只允许常量值,取值范围[-rank(`x`), rank(`x`))。
**输出:**
Tensor具有与输入 `x` 相同的shape。
- 如果轴为()且keep_dims为False则输出一个0维Tensor表示输入Tensor中所有元素的和。
- 如果轴为int取值为2并且keep_dims为False则输出的shape为 :math:`(x_1, x_3, ..., x_R)`
- 如果轴为tuple(int)或list(int),取值为(2, 3)并且keep_dims为False则输出的shape为 :math:`(x_1, x_4, ..., x_R)`
**异常:**
- **TypeError** - `keep_dims` 不是bool。
- **TypeError** - `x` 不是Tensor。
- **ValueError** - `axis` 取值为None。