Skip to content
Related Articles

Related Articles

Improve Article

sympy.stats.Gamma() function in Python

  • Last Updated : 18 Aug, 2020

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

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

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 distribution.

Example #1 :

Python3




# import sympy, Gamma, density, Symbol, pprint
from sympy.stats import Gamma, density
from sympy import Symbol, pprint
  
k = Symbol("k", positive = True)
theta = Symbol("theta", positive = True)
z = Symbol("z")
  
# using sympy.stats.Gamma() method
X = Gamma("x", k, theta)
gamVar = density((X)(z))
  
pprint(gamVar)

Output:

                 -z  
                -----
     -k  k - 1  theta
theta  *z     *e     
---------------------
       Gamma(k)  

Example #2 :

Python3




# import sympy, Gamma, density, Symbol, pprint
from sympy.stats import Gamma, density
from sympy import Symbol, pprint
  
z = Symbol("z")
  
# using sympy.stats.Gamma() method
X = Gamma("x", 1 / 3, 45)
gamVar = density((X)(z))
  
pprint(gamVar)

Output:

           -z     
           ---    
   3 ____   45    
   \/ 75 *e       
------------------
    2/3           
15*z   *Gamma(1/3)



My Personal Notes arrow_drop_up
Recommended Articles
Page :