mindspore.ops.cumsum

mindspore.ops.cumsum(x, axis, dtype=None)[source]

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

\[y_i = x_1 + x_2 + x_3 + ... + x_i\]

Warning

Starting after version 2.9.0, this interface will undergo a non-compatible change:

  • The parameter x will be renamed to input.

  • The parameter axis will be renamed to dim.

The updated signature will be mindspore.ops.cumsum(input, dim, dtype=None).

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]])