2.4K Star 8.2K Fork 4.4K

GVPMindSpore / mindspore

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
cum_sum_doc.yaml 2.43 KB
一键复制 编辑 原始数据 按行查看 历史
chenfei_mindspore 提交于 2024-02-26 16:24 . move doc.yaml to doc dir
cum_sum:
description: |
Computes the cumulative sum of input tensor along axis.
.. math::
y_i = x_1 + x_2 + x_3 + ... + x_i
Args:
exclusive (bool): By default, this op performs an inclusive cumsum, which means that the first
element of the input is identical to the first element of the output. Default: ``False`` .
reverse (bool): If ``True`` , perform inverse cumulative sum. Default: ``False`` .
Inputs:
- **input** (Tensor) - The input Tensor with shape
:math:`(N, *)` where :math:`*` means any number of additional dimensions.
- **axis** (int) - The axis to accumulate the tensor's value. Only constant value is allowed.
Must be in the range [-rank(input), rank(input)).
Outputs:
Tensor, the shape of the output tensor is consistent with the input tensor's.
Raises:
TypeError: If `exclusive` or `reverse` is not a bool.
TypeError: If `axis` is not an int.
Supported Platforms:
``Ascend`` ``GPU`` ``CPU``
Examples:
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> x = Tensor(np.array([[3, 4, 6, 10], [1, 6, 7, 9], [4, 3, 8, 7], [1, 3, 7, 9]]).astype(np.float32))
>>> cumsum = ops.CumSum()
>>> # case 1: along the axis 0
>>> y = cumsum(x, 0)
>>> print(y)
[[ 3. 4. 6. 10.]
[ 4. 10. 13. 19.]
[ 8. 13. 21. 26.]
[ 9. 16. 28. 35.]]
>>> # case 2: along the axis 1
>>> y = cumsum(x, 1)
>>> print(y)
[[ 3. 7. 13. 23.]
[ 1. 7. 14. 23.]
[ 4. 7. 15. 22.]
[ 1. 4. 11. 20.]]
>>> # Next demonstrate exclusive and reverse, along axis 1
>>> # case 3: exclusive = True
>>> cumsum = ops.CumSum(exclusive=True)
>>> y = cumsum(x, 1)
>>> print(y)
[[ 0. 3. 7. 13.]
[ 0. 1. 7. 14.]
[ 0. 4. 7. 15.]
[ 0. 1. 4. 11.]]
>>> # case 4: reverse = True
>>> cumsum = ops.CumSum(reverse=True)
>>> y = cumsum(x, 1)
>>> print(y)
[[23. 20. 16. 10.]
[23. 22. 16. 9.]
[22. 18. 15. 7.]
[20. 19. 16. 9.]]
Python
1
https://gitee.com/mindspore/mindspore.git
git@gitee.com:mindspore/mindspore.git
mindspore
mindspore
mindspore
master

搜索帮助