Thursday, December 11, 2025
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
32440 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6811 POSTS0 COMMENTS
Nicole Veronica
11950 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12023 POSTS0 COMMENTS
Shaida Kate Naidoo
6943 POSTS0 COMMENTS
Ted Musemwa
7193 POSTS0 COMMENTS
Thapelo Manthata
6889 POSTS0 COMMENTS
Umr Jansen
6880 POSTS0 COMMENTS