logsumexp¶
- paddle. logsumexp ( x, axis=None, keepdim=False, name=None ) [source]
-
Calculates the log of the sum of exponentials of
x
alongaxis
.\[logsumexp(x) = \log\sum exp(x)\]- Parameters
-
x (Tensor) – The input Tensor with data type float16, float32 or float64, which have no more than 4 dimensions.
axis (int|list|tuple, optional) – The axis along which to perform logsumexp calculations.
axis
should be int, list(int) or tuple(int). Ifaxis
is a list/tuple of dimension(s), logsumexp is calculated along all element(s) ofaxis
.axis
or element(s) ofaxis
should be in range [-D, D), where D is the dimensions ofx
. Ifaxis
or element(s) ofaxis
is less than 0, it works the same way as \(axis + D\) . Ifaxis
is None, logsumexp is calculated along all elements ofx
. Default is None.keepdim (bool, optional) – Whether to reserve the reduced dimension(s) in the output Tensor. If
keep_dim
is True, the dimensions of the output Tensor is the same asx
except in the reduced dimensions(it is of size 1 in this case). Otherwise, the shape of the output Tensor is squeezed inaxis
. Default is False.name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.
- Returns
-
Tensor, results of logsumexp along
axis
ofx
, with the same data type asx
.
Examples:
>>> import paddle >>> x = paddle.to_tensor([[-1.5, 0., 2.], [3., 1.2, -2.4]]) >>> out1 = paddle.logsumexp(x) >>> out1 Tensor(shape=[], dtype=float32, place=Place(cpu), stop_gradient=True, 3.46912265) >>> out2 = paddle.logsumexp(x, 1) >>> out2 Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True, [2.15317822, 3.15684605])