添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Python in its language allows various mathematical operations, which has manifolds application in scientific domain. One such offering of Python is the inbuilt gamma() function, which numerically computes the gamma value of the number that is passed in the function.

Syntax : math.gamma(x)
Parameters :
x : The number whose gamma value needs to be computed.

Returns : The gamma value, which is numerically equal to “factorial(x-1)”.

Code #1 : Demonstrating the working of gamma()

factorial() vs gamma()

The gamma value can also be found using factorial(x-1) , but the use case of gamma() is because, if we compare both the function to achieve the similar task, gamma() offers better performance.

Code #2 : Comparing factorial() and gamma()

# gamma() vs factorial()
start_fact = time.time()
res_fact = math.factorial(gamma_var - 1 )
print ( "The gamma value using factorial is : "
+ str (res_fact))
print ( "The time taken to compute is : "
+ str (time.time() - start_fact))
print ( '\n' )
start_gamma = time.time()
res_gamma = math.gamma(gamma_var)
print ( "The gamma value using gamma() is : "
+ str (res_gamma))
print ( "The time taken to compute is : "
+ str (time.time() - start_gamma))

Output:

The gamma value using factorial is : 120
The time taken to compute is : 9.059906005859375e-06
The gamma value using gamma() is : 120.0
The time taken to compute is : 5.245208740234375e-06
                
Python | sympy.gamma() method
With the help of sympy.gamma() method, we can find the gamma function in SymPy. gamma(z) represents [Tex]\Gamma(z) = \int_0^\infty t^{z - 1}e^{-t}\, dt, [/Tex] which for positive integer z is the same as [Tex](z - 1)![/Tex]. Syntax: gamma(Z) Parameters: Z - It is the input value to the gamma function. Returns: Returns the gamma function result of t
Pgmagick gamma() method - Python
The gamma() function is an inbuilt function in the Pgmagick library which is used to level of gamma correction. The function returns the true value on success. Syntax: gamma(red, green, blue) Parameters: This function accepts three parameters as red, green and blue which correct the gamma level of red, green and blue color respectively. Return Valu
scipy stats.gamma() | Python
scipy.stats.gamma() is an gamma continuous random variable that is defined with a standard format and some shape parameters to complete its specification. Parameters : -> q : lower and upper tail probability -> x : quantiles -> loc : [optional]location parameter. Default = 0 -> scale : [optional]scale parameter. Default = 1 -> size :
Python - Log Gamma Distribution in Statistics
scipy.stats.loggamma() is a log gamma continuous random variable. It is inherited from the of generic methods as an instance of the rv_continuous class. It completes the methods with details specific for this particular distribution. Parameters : q : lower and upper tail probability x : quantiles loc : [optional]location parameter. Default = 0 scal
Elias Gamma Encoding in Python
The Elias gamma code is a universal code that is used to encode a sequence of positive integers. It is developed by Peter Elias. It is most useful when the upper bound of integers cannot be determined beforehand. Steps in Encoding: To encode a number X, Find the largest N, with [Tex]2^{N}\leq X[/Tex](greater power of 2). Encode N using Unary coding
Wand gamma() function in Python
gamma() allows us to adjust the luminance of an image. Resulting pixels are defined as pixel^(1/gamma). The value of gamma is typically between 0.8 & 2.3 range, and value of 1.0 will not affect the resulting image. Parameters : Parameter Input Type Description adjustment_value numbers.Real value to adjust gamma level. channel basestring optiona
numpy.random.gamma() in Python
With the help of numpy.random.gamma() method, we can get the random samples of gamma distribution and return the random samples of numpy array by using this method. Syntax : numpy.random.gamma(shape, scale=1.0, size=None) Return : Return the random samples of numpy array. Example #1 : In this example we can see that by using numpy.random.gamma() me
sympy.stats.Gamma() function in Python
With the help of sympy.stats.Gamma() method, we can create a continuous random variable with a Gamma distribution. The density of the Gamma distribution is given by with x in [0, 1]. Syntax: sympy.stats.Gamma(name, k, theta) Parameters: k: real number, k>0 theta: real number, theta>0 Returns: a continuous random variable with a Gamma distribu
Elias Gamma Decoding in Python
The Elias gamma code is a universal code that is used to encode a sequence of positive integers. It is developed by Peter Elias. It is most useful when the upper-bound of integers cannot be determined beforehand. Formula: Elias Gamma Coding=Unary(1+floor(log2(x)))+Binary representation of 'x' without MSB Example: Let’s consider an example where we
fabs() method of Python's math Library
fabs() is a method specified in math library in Python 2 and Python 3. Sometimes while computing the difference between 2 numbers to compute the closeness of a number with the other number, we require to find the magnitude of certain number, fabs() can come handy in the cases where we are dealing with ints and want the result in float number to per
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy Got It !
Please go through our recently updated Improvement Guidelines before submitting any improvements.
This article is being improved by another user right now. You can suggest the changes for now and it will be under the article's discussion tab.
You will be notified via email once the article is available for improvement. Thank you for your valuable feedback!
Please go through our recently updated Improvement Guidelines before submitting any improvements.
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.