Diving deeper into data science I started to brush up my knowledge about math especially statistics.
The Mother of all Distributions
The normal distribution was formulated by Carl Friedrich Gauß in 1809 and can be implemented in Python like the following :
def normal_distribution_pdf(x, mu=0, sigma=1):
sqrt_two_pi = math.sqrt(2*math.pi)
return (1 / (sqrt_two_pi * sigma)) * math.exp(-((x - mu) ** 2) / (2 * sigma ** 2))
Scipy
For professional use you should packages like scipy to generate the pdf of a normal distribution
import matplotlib.pyplot as plt
import numpy as np
from scipy.stats import norm
if __name__ == '__main__':
fig, ax = plt.subplots(1, 1)
x = np.linspace(norm.ppf(0.01), norm.ppf(0.99), 100)
ax.plot(x, norm.pdf(x), 'r-', label='norm pdf')
plt.savefig("pdf.png")
Further reading
https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.norm.html