Friday, October 10, 2025
HomeLanguagesSympy stats.ContinuousRV() in Python

Sympy stats.ContinuousRV() in Python

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.




# Import sympy and ContinuousRV
from sympy.stats import ContinuousRV, P, E
from sympy import Symbol, pprint, sqrt
  
z = Symbol("z")
pdf = sqrt(2)*z / pi
  
# Using sympy.stats.ContinuousRV() method
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 :




# Import sympy and ContinuousRV
from sympy.stats import ContinuousRV, P, E
from sympy import Symbol, pprint, sqrt
  
z = Symbol("z")
pdf = sqrt(2)*z / pi
  
# Using sympy.stats.ContinuousRV() method
X = ContinuousRV(z, pdf)
  
print(P(X>0))


Output :

1/2

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

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6718 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7100 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS