- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python – scipy.special.logsumexp
The scipy.special package contains a set of different functionalities that are used for mathematical physics. One of them is the logsumexp() function. This function is used to compute the log of the sum of exponentials of input elements. Let us take a couple of examples and see how to use this function.
Syntax
scipy.special.logsumexp(x)
where, x is the input value.
Example 1
Let us consider the following example −
# Import logsumexp from scipy.special from scipy.special import logsumexp import numpy as np # Input array a = np.arange(10) print("Input Array:
", a) # logsum() function res = logsumexp(a) print("logsumexp of a:", res)
Output
It will produce the following output −
Input Array: [0 1 2 3 4 5 6 7 8 9] logsumexp of a: 9.45862974442671
Example 2
Let us take another example −
# Import logsumexp from scipy.special from scipy.special import logsumexp # logsumexp function res = logsumexp(a=[5,6], b=[4,-2], return_sign=True) # Display the logsumexp values print("Logsumexp values are :", res)
Here, return_sign is an optional parameter. If it is True, then the result will be a pair containing sign information. If return_sign=False, then the results that are negative will be returned as NaN. Default is False.
Output
The above program will generate the following output −
Logsumexp values are : (5.36225391235589, -1.0)
- Related Articles
- How do I install Python SciPy?
- String Special Operators in Python
- What are various sub-packages in Python SciPy library?
- How to solve triangular matrix equations using Python SciPy?
- Special Syntax with Parentheses in Python
- __name__ (A Special variable) in Python
- How can discrete Fourier transform be performed in SciPy Python?
- How to solve a circulant matrix equation using Python SciPy?
- Groups of Special-Equivalent Strings in Python
- Explain how Nelder-Mead algorithm can be implemented using SciPy Python?
- What is the use of scipy.interpolate.interp1d class of SciPy python library?
- How to solve Hermitian positive-banded matrix equation using Python SciPy?
- Mathematical Functions in Python - Special Functions and Constants
- Calculating Euclidean distance using SciPy
- How to use special characters in Python Regular Expression?
- Calculating the Manhattan distance using SciPy

Advertisements