The cumulative sum of the elements along a given axis. Note: The first element of the result is the same as the first element of the input. .. note:: Alias Support: The parameter name ``input`` can be used as an alias for ``x``, and ``dim`` can be used as an alias for
(
x: Tensor,
axis: int | None = None,
dtype: DTypeLike | None = None,
name: str | None = None,
*,
out: Tensor | None = None,
)
| 3053 | |
| 3054 | @param_two_alias(["x", "input"], ["axis", "dim"]) |
| 3055 | def cumsum( |
| 3056 | x: Tensor, |
| 3057 | axis: int | None = None, |
| 3058 | dtype: DTypeLike | None = None, |
| 3059 | name: str | None = None, |
| 3060 | *, |
| 3061 | out: Tensor | None = None, |
| 3062 | ) -> Tensor: |
| 3063 | """ |
| 3064 | The cumulative sum of the elements along a given axis. |
| 3065 | |
| 3066 | Note: |
| 3067 | The first element of the result is the same as the first element of the input. |
| 3068 | |
| 3069 | .. note:: |
| 3070 | Alias Support: The parameter name ``input`` can be used as an alias for ``x``, and ``dim`` can be used as an alias for ``axis``. |
| 3071 | For example, ``cumsum(input=tensor_x, dim=1, ...)`` is equivalent to ``cumsum(x=tensor_x, axis=1, ...)``. |
| 3072 | |
| 3073 | Args: |
| 3074 | x (Tensor): The input tensor needed to be cumsumed. |
| 3075 | alias: ``input``. |
| 3076 | axis (int, optional): The dimension to accumulate along. -1 means the last dimension. The default (None) is to compute the cumsum over the flattened array. |
| 3077 | alias: ``dim``. |
| 3078 | dtype (str|paddle.dtype|np.dtype|None, optional): The data type of the output tensor, can be bfloat16, float16, float32, float64, int32, int64, complex64, complex128. By default, it is int64 if the input x is int8/int16/int32; otherwise, it is None. If it is not None, the input tensor is casted to dtype before the operation is performed. This is useful for preventing data type overflows. |
| 3079 | name (str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`. |
| 3080 | out (Tensor, optional): The output tensor. If provided, the result will be stored in this tensor. |
| 3081 | |
| 3082 | Returns: |
| 3083 | Tensor, the result of cumsum operator. |
| 3084 | |
| 3085 | Examples: |
| 3086 | .. code-block:: pycon |
| 3087 | |
| 3088 | >>> import paddle |
| 3089 | |
| 3090 | >>> data = paddle.arange(12) |
| 3091 | >>> data = paddle.reshape(data, (3, 4)) |
| 3092 | |
| 3093 | >>> y = paddle.cumsum(data) |
| 3094 | >>> y |
| 3095 | Tensor(shape=[12], dtype=int64, place=Place(cpu), stop_gradient=True, |
| 3096 | [0 , 1 , 3 , 6 , 10, 15, 21, 28, 36, 45, 55, 66]) |
| 3097 | |
| 3098 | >>> y = paddle.cumsum(data, axis=0) |
| 3099 | >>> y |
| 3100 | Tensor(shape=[3, 4], dtype=int64, place=Place(cpu), stop_gradient=True, |
| 3101 | [[0 , 1 , 2 , 3 ], |
| 3102 | [4 , 6 , 8 , 10], |
| 3103 | [12, 15, 18, 21]]) |
| 3104 | |
| 3105 | >>> y = paddle.cumsum(data, axis=-1) |
| 3106 | >>> y |
| 3107 | Tensor(shape=[3, 4], dtype=int64, place=Place(cpu), stop_gradient=True, |
| 3108 | [[0 , 1 , 3 , 6 ], |
| 3109 | [4 , 9 , 15, 22], |
| 3110 | [8 , 17, 27, 38]]) |
| 3111 | |
| 3112 | >>> y = paddle.cumsum(data, dtype='float64') |
nothing calls this directly
no test coverage detected