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

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

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

sympy.stats.Binomial()方法的帮助下,我们可以创建一个表示二项分布的有限随机变量。

二项分布是重复多次的实验或调查中成功或失败结果的概率。

Syntax: sympy.stats.Binomial(name, n, p, succ=1, fail=0)

Parameters:
 name: distribution name
 n: Positive Integer, represents number of trials
 p: Rational Number between 0 and 1, represents probability of success
 succ: Represents event of success, by default is 1
 fail: Represents event of failure, by default is 0

示例 #1:

Python3
# Import sympy, Binomial, density
from sympy.stats import Binomial, density
  
# Using sympy.stats.Binomial() method
X = Binomial('X', 4, 1 / 3)
binDist = density(X).dict
  
print(binDist)


Python3
# Import sympy, Binomial, density
from sympy.stats import Binomial, density
  
# Using sympy.stats.Binomial() method
X = Binomial('X', 4, 1 / 3, 1 / 2)
binDist = density(X).dict
  
print(binDist)


输出 :

{0: 16/81, 1: 32/81, 2: 8/27, 3: 8/81, 4: 1/81}



示例 #2:

Python3

# Import sympy, Binomial, density
from sympy.stats import Binomial, density
  
# Using sympy.stats.Binomial() method
X = Binomial('X', 4, 1 / 3, 1 / 2)
binDist = density(X).dict
  
print(binDist)

输出 :

{0: 16/81, 1/2: 32/81, 2: 1/81, 3/2: 8/81, 1: 8/27}