Tuesday, June 16, 2026
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
32516 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