Open In App

sympy.stats.FiniteRV() function in Python

Last Updated : 01 Jun, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

With the help of sympy.stats.FiniteRV() method, we can create a random variable gives a dictionary of density by using sympy.stats.FiniteRV() method.

Syntax : sympy.stats.FiniteRV(name, dict)

Return : Return the variable having dictionary of density.

Example #1 :
In this example, we can see that by using sympy.stats.FiniteRV() method, we are able to create the random variable which denotes the dictionary of densities by using this method.




# Import sympy and FiniteRV
from sympy.stats import FiniteRV, P, E
  
  
# Using sympy.stats.FiniteRV() method
density = {0: .1, 1: .2, 2: .3, 3: .4}
X = FiniteRV('X', density)
print(E(X))
  
gfg = P(X > 2)
print(gfg)


Output :

2.00000000000000
0.40000000000000

Example #2 :




# Import sympy and FiniteRV
from sympy.stats import FiniteRV, P, E
  
  
# Using sympy.stats.FiniteRV() method
density = {0: .11, 1: .20, 2: .13, 3: .4, 4: 0.16}
X = FiniteRV('X', density)
print(E(X))
  
gfg = P(X >= 3)
print(gfg)


Output :

2.30000000000000
0.56000000000000


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads