Learn Before
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 for a given value , given a mean and standard deviation . 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: .
0
1
Updated 2026-05-02
Tags
D2L
Dive into Deep Learning @ D2L