Code

Normal Distribution Probability Density Function Code

The mathematical formula for the normal distribution's probability density function can be directly implemented in Python. Using standard libraries like math and numpy (or their deep learning equivalents in PyTorch, JAX, or TensorFlow), a function can be defined to calculate the probability density pp for a given value xx, given a mean μ\mu and standard deviation σ\sigma. The code implementation is as follows:

def normal(x, mu, sigma): p = 1 / math.sqrt(2 * math.pi * sigma**2) return p * np.exp(-0.5 * (x - mu)**2 / sigma**2)

This runnable implementation aligns with the formal definition: p(x)=12πσ2exp(12σ2(xμ)2)p(x) = \frac{1}{\sqrt{2 \pi \sigma^2}} \exp\left(-\frac{1}{2 \sigma^2} (x - \mu)^2\right).

0

1

Updated 2026-05-02

Contributors are:

Who are from:

Tags

D2L

Dive into Deep Learning @ D2L