Open In App

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

Example #1 :






# 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 :




# 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)

Article Tags :