paddle.fluid.layers.cumsum(x, axis=None, exclusive=None, reverse=None)[source]

The cumulative sum of the elements along a given axis. By default, the first element of the result is the same of the first element of the input. If exlusive is true, the first element of the result is 0.

  • x (Variable) – Input of cumsum operator, the Tensor/LoDTensor needed to be cumsumed.

  • axis (int, optional) – The dimension to accumulate along. -1 means the last dimension. Default is -1.

  • exclusive (bool, optional) – Whether to perform exclusive cumsum. Default is False.

  • reverse (bool, optional) – If true, the cumsum is performed in the reversed direction. Default is False.


The result of cumsum operator, output of cumsum operator.

Return type



import paddle.fluid as fluid
data ="input", shape=[32, 784])
result = fluid.layers.cumsum(data, axis=0)