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

25 lines
1.1 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.sum
==================
.. py:function:: mindspore.ops.sum(x, dim=None, keepdim=False, *, dtype=None)
计算Tensor指定维度元素的和。
参数:
- **x** (Tensor) - 输入Tensor。
- **dim** (Union[None, int, tuple(int), list(int)]) - 求和的维度。如果 `dim` 为None对Tensor中的所有元素求和。
如果 `dim` 为int组成的tuple或list将对tuple中的所有维度求和取值范围必须在 :math:`[-x.ndim, x.ndim)` 。默认值None。
- **keepdim** (bool) - 是否保持输出Tensor的维度如果为True保持对应的维度且长度为1。如果为False不保持维度。默认值False。
关键字参数:
- **dtype** (:class:`mindspore.dtype`, 可选) - 期望输出Tensor的类型。默认值None。
返回:
Tensor `x` 指定维度的和。
异常:
- **TypeError** - `x` 不是Tensor类型。
- **TypeError** - `dim` 类型不是inttulpe(int)list(int)或None。
- **ValueError** - `dim` 取值不在 :math:`[-x.ndim, x.ndim)` 范围。
- **TypeError** - `keepdim` 不是Tensor类型。