mindspore.mint.cumsum
- mindspore.mint.cumsum(input, dim, dtype=None)[source]
Return the cumulative sum along the given dimension of the tensor.
\[y_i = x_1 + x_2 + x_3 + ... + x_i\]- Parameters
input (Tensor) – The input tensor.
dim (int) – Specify the dimension for computation.
dtype (
mindspore.dtype, optional) – The data type returned. DefaultNone.
- Returns
Tensor
- Supported Platforms:
Ascend
Examples
>>> import mindspore >>> x = mindspore.tensor([[3, 4, 6, 10], [1, 6, 7, 9], [4, 3, 8, 7], [1, 3, 7, 9]]) >>> # case 1: along the dim 0 >>> mindspore.mint.cumsum(x, 0) Tensor(shape=[4, 4], dtype=Int64, value= [[ 3, 4, 6, 10], [ 4, 10, 13, 19], [ 8, 13, 21, 26], [ 9, 16, 28, 35]]) >>> # case 2: along the dim 1 >>> mindspore.mint.cumsum(x, 1) Tensor(shape=[4, 4], dtype=Int64, value= [[ 3, 7, 13, 23], [ 1, 7, 14, 23], [ 4, 7, 15, 22], [ 1, 4, 11, 20]])