mindspore.Tensor.cumsum
- Tensor.cumsum(axis=None, dtype=None)[source]
Return the cumulative sum of the elements along a given axis.
Note
If
self.dtype
isint8
,int16
orbool
, the result dtype will be elevated toint32
,int64
is not supported.- Parameters
axis (int, optional) – Axis along which the cumulative sum is computed. The default (None) is to compute the cumsum over the flattened array.
dtype (
mindspore.dtype
, optional) – If not specified, stay the same as original tensor, unless it has an integer dtype with a precision less thanfloat32
. In that case,float32
is used. Default: None.
- Returns
Tensor.
See also
mindspore.Tensor.sum()
: Return sum of tensor elements over a given axis.- Raises
ValueError – If the axis is out of range.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import numpy as np >>> from mindspore import Tensor >>> a = Tensor(np.ones((3,3)).astype("float32")) >>> output = a.cumsum(axis=0) >>> print(output) [[1. 1. 1.] [2. 2. 2.] [3. 3. 3.]]