mindspore.mint.logsumexp

View Source On Gitee
mindspore.mint.logsumexp(input, dim, keepdim=False)[source]

Calculate the logarithm of the sum of exponentiations of all elements along the specified dim dimension of the input tensor.

\[logsumexp(input) = \log(\sum(e^{input-input_{max}})) + input_{max}\]

Warning

This is an experimental API that is subject to change or deletion.

Parameters
  • input (Tensor) – The input tensor.

  • dim (Union[int, tuple(int), list(int)]) – Specify the dimension for computation. If dim is (), compute all elements in the input.

  • keepdim (bool, optional) – Whether the output tensor has dim retained. Default False.

Returns

Tensor

Supported Platforms:

Ascend

Examples

>>> import numpy as np
>>> import mindspore
>>> x = mindspore.tensor(np.random.randn(3, 4, 5, 6).astype(np.float32))
>>> output = mindspore.mint.logsumexp(x, 1, keepdim=True)
>>> print(output.shape)
(3, 1, 5, 6)