With the help of sympy.stats.Binomial() method, we can create a Finite Random Variable representing a binomial distribution.
A binomial distribution is the probability of a SUCCESS or FAILURE outcome in an experiment or survey that is repeated multiple times.
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
Example #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) |
Output :
{0: 16/81, 1: 32/81, 2: 8/27, 3: 8/81, 4: 1/81}
Example #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) |
Output :
{0: 16/81, 1/2: 32/81, 2: 1/81, 3/2: 8/81, 1: 8/27}