# logcumsumexp¶

paddle. logcumsumexp ( x, axis=None, dtype=None, name=None ) [source]

The logarithm of the cumulative summation of the exponentiation of the elements along a given axis.

For summation index j given by axis and other indices i, the result is

$logcumsumexp(x)_{ij} = log \sum_{i=0}^{j}exp(x_{ij})$

Note

The first element of the result is the same as the first element of the input.

Parameters
• x (Tensor) – The input tensor.

• axis (int, optional) – The dimension to do the operation along. -1 means the last dimension. The default (None) is to compute the cumsum over the flattened array.

• dtype (str, optional) – The data type of the output tensor, can be float32, float64. If specified, the input tensor is casted to dtype before the operation is performed. This is useful for preventing data type overflows. The default value is None.

• name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

Tensor, the result of logcumsumexp operator.

Examples

import paddle

data = paddle.arange(12, dtype='float64')
data = paddle.reshape(data, (3, 4))

# [ 0.         1.3132617  2.4076061  3.4401898  4.4519143  5.4561934
#   6.4577627  7.4583397  8.458551   9.45863   10.458658  11.458669 ]

y = paddle.logcumsumexp(data, axis=0)
# [[ 0.        1.        2.        3.      ]
#  [ 4.01815   5.01815   6.01815   7.01815 ]
#  [ 8.018479  9.018479 10.018479 11.018479]]

y = paddle.logcumsumexp(data, axis=-1)
# [[ 0.         1.3132617  2.4076061  3.4401898]
#  [ 4.         5.3132615  6.407606   7.44019  ]
#  [ 8.         9.313262  10.407606  11.440189 ]]

y = paddle.logcumsumexp(data, dtype='float64')
print(y.dtype)