logaddexp(x1, x2, out=None, **kwargs)

Logarithm of the sum of exponentiations of the inputs.

Calculates log(exp(x1) + exp(x2)). This function is useful in statistics where the calculated probabilities of events may be so small as to exceed the range of normal floating point numbers. In such cases the logarithm of the calculate probability is stored. This function allows adding probabilities stored in such a fashion.

  • x1 (ndarray or scalar) – Array of multipliers.

  • x2 (ndarray or scalar, int) – Array of twos exponents.

  • out (ndarray, optional) – A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not, a freshly-allocated array is returned.


y – Logarithm of exp(x1) + exp(x2). This is a scalar if both x1 and x2 are scalars.

Return type

ndarray or scalar


>>> prob1 = np.log(1e-50)
>>> prob2 = np.log(2.5e-50)
>>> prob12 = np.logaddexp(prob1, prob2)
>>> prob12
>>> np.exp(prob12)