當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Python sympy.stats.NegativeMultinomial()用法及代碼示例


借助於sympy.stats.NegativeMultinomial()方法,我們可以創建具有負多項式分布的離散隨機變量。

用法:sympy.stats.NegativeMultinomial(syms, k, p)

參數:
 syms:the symbol
 k:number of failures before the experiment is stopped, a positive integer
 p:event probabilites, p>= 0 and p<= 1

返回:a discrete random variable with Negative Multinomial Distribution.

範例1:

Python3

# import sympy, NegativeMultinomia, density, symbols 
from sympy.stats import density 
from sympy.stats.joint_rv_types import NegativeMultinomial 
from sympy import symbols, pprint 
  
p1, p2, p3 = symbols('p1, p2, p3', positive = True) 
x1, x2, x3 = symbols('x1, x2, x3', nonnegative = True, integer = True) 
  
# using sympy.stats.NegativeMultinomial() method 
N = NegativeMultinomial('N', 3, p1, p2, p3) 
negMulti = density(N)(x1, x2, x3) 
  
pprint(negMulti)

輸出:

  x1   x2   x3                    3                        
p1  *p2  *p3  *(-p1 - p2 - p3 + 1) *Gamma(x1 + x2 + x3 + 3)
-----------------------------------------------------------
                       2*x1!*x2!*x3!   

範例2:



Python3

# import sympy, NegativeMultinomia, density, symbols 
from sympy.stats import density 
from sympy.stats.joint_rv_types import NegativeMultinomial 
from sympy import symbols, pprint 
  
x1, x2, x3 = symbols('x1, x2, x3', nonnegative = True, integer = True) 
  
# using sympy.stats.NegativeMultinomial() method 
N = NegativeMultinomial('N', 2, 1 / 3, 1 / 2) 
negMulti = density(N)(x1, x2, x3) 
  
pprint(negMulti)

輸出:

 -x2  -x1                        
2   *3   *Gamma(x1 + x2 + x3 + 2)
---------------------------------
            36*x1!*x 



相關用法


注:本文由純淨天空篩選整理自ravikishor大神的英文原創作品 sympy.stats.NegativeMultinomial() function in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。