Did I find the right examples for you? yes no

sympy.stats.density

All Samples(25)  |  Call(21)  |  Derive(0)  |  Import(4)
```Probability density of a random expression

Optionally given a second condition

This density will take on different forms for different types of
probability spaces.
Discrete variables produce Dicts.
Continuous variables produce Lambdas.

Examples(more...)
```

```        def density(expr, condition=None, evaluate=True, **kwargs):
"""
Probability density of a random expression

Optionally given a second condition

This density will take on different forms for different types of
probability spaces.
Discrete variables produce Dicts.
Continuous variables produce Lambdas.

Examples
========

>>> from sympy.stats import density, Die, Normal
>>> from sympy import Symbol

>>> x = Symbol('x')
>>> D = Die('D', 6)
>>> X = Normal(x, 0, 1)

>>> density(D).dict
{1: 1/6, 2: 1/6, 3: 1/6, 4: 1/6, 5: 1/6, 6: 1/6}
>>> density(2*D).dict
{2: 1/6, 4: 1/6, 6: 1/6, 8: 1/6, 10: 1/6, 12: 1/6}
>>> density(X)(x)
sqrt(2)*exp(-x**2/2)/(2*sqrt(pi))
"""
return Density(expr, condition).doit(evaluate=evaluate, **kwargs)
```

```from sympy import (EmptySet, FiniteSet, S, Symbol, Interval, exp, erf, sqrt,
symbols, simplify, Eq, cos, And, Tuple, Or, Dict, sympify, binomial,
factor)
from sympy.stats import (DiscreteUniform, Die, Bernoulli, Coin, Binomial,
Hypergeometric, P, E, variance, covariance, skewness, sample, density,
```
```    assert covariance(X, Y) == S.Zero
assert covariance(X, X + Y) == variance(X)
assert density(Eq(cos(X*S.Pi), 1))[True] == S.Half
assert correlation(X, Y) == 0
assert correlation(X, Y) == correlation(Y, X)
```
```    assert P(Eq(X + Y, 12), Eq(X, 6)) == S.One/6

assert density(X + Y) == density(Y + Z) != density(X + X)
d = density(2*X + Y**Z)
assert d[S(22)] == S.One/108 and d[S(4100)] == S.One/216 and S(3130) not in d
```

```from sympy import (EmptySet, FiniteSet, S, Symbol, Interval, exp, erf, sqrt,
symbols, simplify, Eq, cos, And, Tuple, integrate, oo, sin, Sum, Basic,
DiracDelta)
from sympy.stats import (Die, Normal, Exponential, P, E, variance, covariance,
skewness, density, given, independent, dependent, where, pspace,
```
```def test_normality():
X, Y = Normal('X', 0, 1), Normal('Y', 0, 1)
x, z = symbols('x, z', real=True)
dens = density(X - Y, Eq(X + Y, z))

```
```def test_Density():
X = Die('X', 6)
d = Density(X)
assert d.doit() == density(X)

```

```from sympy.stats import (P, E, where, density, variance, covariance, skewness,
given, pspace, cdf, ContinuousRV, sample,
Arcsin, Benini, Beta, BetaPrime, Cauchy,
Chi, ChiSquared,
ChiNoncentral, Dagum, Erlang, Exponential,
```
```    assert simplify(E(Y)) == mu
assert simplify(variance(Y)) == sigma**2
pdf = density(Y)
x = Symbol('x')
assert (pdf(x) ==
```
```def test_conditional_1d():
X = Normal('x', 0, 1)
Y = given(X, X >= 0)

assert density(Y) == 2 * density(X)
```
```    assert pspace(B).domain.set == Interval(0, 1)

dens = density(B)
x = Symbol('x')
assert dens(x) == x**(a - 1)*(1 - x)**(b - 1) / beta(a, b)
```

```from sympy.stats.drv_types import (PoissonDistribution, GeometricDistribution,
Poisson)
from sympy.abc import x
from sympy import S, Sum
from sympy.stats import E, variance, density
```
```    assert E(x) == l
assert variance(x) == l
assert density(x) == PoissonDistribution(l)
assert isinstance(E(x, evaluate=False), Sum)
assert isinstance(E(2*x, evaluate=False), Sum)
```