Sunday, June 14, 2026
HomeLanguagesSympy – stats.DiscreteUniform() in Python

Sympy – stats.DiscreteUniform() in Python

With the help of sympy.stats.DiscreteUniform() method, we can get the random variable who is representing the discrete uniform values for input by using sympy.stats.DiscreteUniform() method.

Syntax : sympy.stats.DiscreteUniform(list/tuple)
Return : Return the discrete uniform value.

Example #1 :
In this example we can see that by using sympy.stats.DiscreteUniform() method, we are able to get the random variable representing the discrete uniform value by using this method.




# Import sympy and DiscreteUniform
from sympy.stats import DiscreteUniform, density
from sympy import symbols
  
# Using stats.DiscreteUniform() method
X = DiscreteUniform('X', symbols('g f g'))
gfg = density(X).dict
  
print(gfg)


Output :

{g: 1/3, f: 1/3}

Example #2 :




# Import sympy and DiscreteUniform
from sympy.stats import DiscreteUniform, density
from sympy import symbols
  
# Using stats.DiscreteUniform() method
Y = DiscreteUniform('Y', list(range(5))) 
gfg = density(Y).dict
  
print(gfg)


Output :

{0: 1/5, 1: 1/5, 2: 1/5, 3: 1/5, 4: 1/5}

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

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS