mindspore.ops.cumsum

View Source On Gitee
mindspore.ops.cumsum(x, axis, dtype=None)[source]

Return the cumulative sum along the given axis of the tensor.

yi=x1+x2+x3+...+xi
Parameters
  • x (Tensor) – The input tensor.

  • axis (int) – Specify the axis for computation.

  • dtype (mindspore.dtype, optional) – The data type returned. Default None .

Returns

Tensor

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> input = mindspore.tensor([[1, 2, 3],
...                           [4, 5, 6]], mindspore.int32)
>>> mindspore.ops.cumsum(input, axis=0)
Tensor(shape=[2, 3], dtype=Int32, value=
[[1, 2, 3],
 [5, 7, 9]])
>>> mindspore.ops.cumsum(input, axis=1)
Tensor(shape=[2, 3], dtype=Int32, value=
[[ 1,  3,  6],
 [ 4,  9, 15]])