📜  Python中的 sympy.stats.Gamma()函数

📅  最后修改于: 2022-05-13 01:54:24.751000             🧑  作者: Mango

Python中的 sympy.stats.Gamma()函数

借助sympy.stats.Gamma()方法,我们可以创建具有 Gamma 分布的连续随机变量。 Gamma 分布的密度由下式给出

x 在 [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.

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


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)


输出:

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

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

输出:

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