Jupyter Snippet CB2nd 04_stats
Jupyter Snippet CB2nd 04_stats
15.4. Computing exact probabilities and manipulating random variables
from sympy import *
from sympy.stats import *
init_printing()
X, Y = Die('X', 6), Die('Y', 6)
P(Eq(X, 3))
P(X > 3)
P(X > Y)
P(X + Y > 6, X < 5)
Z = Normal('Z', 0, 1) # Gaussian variable
P(Z > pi)
E(Z**2), variance(Z**2)
f = density(Z)
var('x')
f(x)
%matplotlib inline
plot(f(x), (x, -6, 6))
Eq(Integral(f(x), (x, pi, oo)),
simplify(integrate(f(x), (x, pi, oo))))