Python math.lgamma() Method
Python math.lgamma(x) The method returns the natural logarithm of the gamma value of a number.
We can also use the math.gamma() method to find the gamma value, and then use the math.log() method to compute the natural logarithm of that value.
The gamma value equals factorial(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, a ValueError is returned. If it is not a number, a TypeError is returned..
Return Value
A floating-point value representing the log-gamma value of a number.
Example
The following example computes the natural log-gamma value of different numbers:
Example
Import the math package
import
math
Compute the natural log-gamma value of different numbers
(
math
.
lgamma
(
7
)
)
(
math
.
lgamma
(
4.2
)
)
Output result:
6.579251212010102
-1.8075166614192908
Python math Module