Sympy stats.ContinuousRV() in Python
Last Updated :
08 Jun, 2020
With the help of sympy.stats.ContinuousRV()
method, we can get the continuous random variable which represents the Continuous Random Variable distribution.
Syntax : sympy.stats.ContinuousRV(symbol, density, set=Interval(- oo, oo))
Parameter :
1) Density – represents the probability density function.
2) set – represent the reason where density function is valid.
Return : Return the continuous random variable.
Example #1 :
In this example we can see that by using sympy.stats.ContinuousRV()
method, we are able to get the continuous random variable representing Continuous Random Variable distribution by using this method.
from sympy.stats import ContinuousRV, P, E
from sympy import Symbol, pprint, sqrt
z = Symbol( "z" )
pdf = sqrt( 2 ) * z / pi
X = ContinuousRV(z, pdf)
gfg = density(X)
pprint(gfg)
|
Output :
ContinuousDistributionHandmade(Lambda(z, Piecewise((sqrt(2)*z/pi, (z >= -oo) &
(z < oo)), (0, True))), Interval(-oo, oo))
Example #2 :
from sympy.stats import ContinuousRV, P, E
from sympy import Symbol, pprint, sqrt
z = Symbol( "z" )
pdf = sqrt( 2 ) * z / pi
X = ContinuousRV(z, pdf)
print (P(X> 0 ))
|
Output :
1/2
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...