HomeLanguagessympy.stats.Multinomial() function in Python

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




# import sympy, Multinomial, density, symbols
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)
  
# Using sympy.stats.Multinomial() method
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




# import sympy, Multinomial, density, symbols
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)
  
# Using sympy.stats.Multinomial() method
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      
\                                

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32705 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7076 POSTS0 COMMENTS
Nicole Veronica
12212 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12303 POSTS0 COMMENTS
Shaida Kate Naidoo
7198 POSTS0 COMMENTS
Ted Musemwa
7457 POSTS0 COMMENTS
Thapelo Manthata
7175 POSTS0 COMMENTS
Umr Jansen
7162 POSTS0 COMMENTS