sympy.stats.Multinomial() function in Python
With the help of sympy.stats.Multinomial() method, we can create a discrete random variable with Multinomial Distribution.
A multinomial distribution is the probability distribution of the outcomes from a multinomial experiment.
Syntax: sympy.stats.Multinomial(syms, n, p)
Parameters:
syms: the symbol
n: is the number of trials, a positive integer
p: event probabilites, p>= 0 and p<= 1
Returns: a discrete random variable with Multinomial Distribution
Example #1 :
Python3
from sympy.stats.joint_rv_types import Multinomial
from sympy.stats import density
from sympy import symbols, pprint
x1, x2, x3 = symbols( 'x1, x2, x3' , nonnegative = True , integer = True )
p1, p2, p3 = symbols( 'p1, p2, p3' , positive = True )
M = Multinomial( 'M' , 3 , p1, p2, p3)
multiDist = density(M)(x1, x2, x3)
pprint(multiDist)
|
Output :
/ x1 x2 x3
|6*p1 *p2 *p3
|---------------- for x1 + x2 + x3 = 3
< x1!*x2!*x3!
|
| 0 otherwise
\
Example #2 :
Python3
from sympy.stats.joint_rv_types import Multinomial
from sympy.stats import density
from sympy import symbols, pprint
x1, x2, x3 = symbols( 'x1, x2, x3' , nonnegative = True , integer = True )
M = Multinomial( 'M' , 4 , 0 , 1 , 0 )
multiDist = density(M)(x1, x2, x3)
pprint(multiDist)
|
Output :
/ x1 x3
| 24*0 *0
|----------- for x1 + x2 + x3 = 4
<x1!*x2!*x3!
|
| 0 otherwise
\
Last Updated :
18 Aug, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...