# Logarithm of the sum of exponentiations of the inputs in Numpy

NumpyServer Side ProgrammingProgramming

#### Python Data Science basics with Numpy, Pandas and Matplotlib

Most Popular

63 Lectures 6 hours

#### Data Analysis using NumPy and Pandas

19 Lectures 8 hours

#### Numpy with Python

Most Popular

12 Lectures 3 hours

To get the Logarithm of the sum of exponentiations of the inputs, use the numpy.logaddexp() method in Python Numpy.

Calculate 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 calculated probability is stored. This function allows adding probabilities stored in such a fashion.

NumPy offers comprehensive mathematical functions, random number generators, linear algebra routines, Fourier transforms, and more. It supports a wide range of hardware and computing platforms, and plays well with distributed, GPU, and sparse array libraries.

## Steps

At first, import the required library −

import numpy as np

one = np.log(1e-50)
two = np.log(2.5e-50)

print("Value 1...\n", one)
print("Value 2...\n", two)

To get the Logarithm of the sum of exponentiations of the inputs, use the numpy.logaddexp() method in Python Numpy −

res = np.logaddexp(one, two)
print("\nLogarithm of the sum of exponentiations...\n",res)

## Example

import numpy as np

# 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 calculated probability is stored.
# This function allows adding probabilities stored in such a fashion.

one = np.log(1e-50)
two = np.log(2.5e-50)

print("Value 1...\n", one)
print("Value 2...\n", two)

# To get the Logarithm of the sum of exponentiations of the inputs, use the numpy.logaddexp() method in Python Numpy
print("\nLogarithm of the sum of exponentiations...\n",res)

## Output

Value 1...
-115.12925464970229
Value 2...
-114.21296391782813

Logarithm of the sum of exponentiations...
-113.87649168120691
Updated on 07-Feb-2022 12:55:34