Python math.lgamma() Method
Python math.lgamma(x)The method returns the natural logarithm gamma value of a number.
We can also use themath.gamma()method to find the gamma value, and then use themath.log()method to calculate the natural logarithm of that value.
The gamma value is equal tofactorial(x-1)。
Python Version: 3.2
Syntax
The syntax of the math.lgamma() method is as follows:
math.lgamma(x)
Parameter Description:
- x-- Required, a number. If the number is a negative integer, ValueError is returned. If it is not a number, TypeError is returned.
Return Value
A floating-point value representing the log gamma value of a number.
Example
The following example calculates the natural log gamma values of different numbers:
Example
# Import the math package
import math
# Calculate the natural log gamma value of different numbers
print (math.lgamma(7))
print (math.lgamma(-4.2))
import math
# Calculate the natural log gamma value of different numbers
print (math.lgamma(7))
print (math.lgamma(-4.2))
Output result:
6.579251212010102 -1.8075166614192908Other Extensions
Python math Module