- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

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

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

Log input −

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

# Display the log input −

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. # Log input one = np.log(1e-50) two = np.log(2.5e-50) # Display the log input 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)

## Output

Value 1... -115.12925464970229 Value 2... -114.21296391782813 Logarithm of the sum of exponentiations... -113.87649168120691

- Related Questions & Answers
- Logarithm of the sum of exponentiations of the inputs in base-2 in Numpy
- Return the ceil of the inputs in Numpy
- Return the truncated value of the inputs in Numpy
- Return the base 10 logarithm of the input array element-wise in Numpy
- Return the natural logarithm of one plus the input array element-wise in Numpy
- Return the largest integer smaller or equal to the division of the inputs in Numpy
- Return the sum along diagonals of the masked array in Numpy
- Compute the sign and natural logarithm of the determinant of an array in Python
- How to compute the Logarithm of elements of a tensor in PyTorch?
- Return the base 2 logarithm of the input array in Python
- Get the base 10 logarithm of a value in Java
- How to find the sum of all elements of a given matrix using Numpy?
- Compute the square root of complex inputs with scimath in Python
- Get the number of elements of the Masked Array in Numpy
- How to find the sum of rows and columns of a given matrix using Numpy?