Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
30 lines (22 sloc) 646 Bytes
"""
Code by Tae-Hwan Hung(@graykode)
https://en.wikipedia.org/wiki/Normal_distribution
"""
import numpy as np
from matplotlib import pyplot as plt
def normal(x, n):
u = x.mean()
s = x.std()
# normalization
x = (x - u) / s
# divide [x.min(), x.max()] by n
x = np.linspace(x.min(), x.max(), n)
a = ((x - 0) ** 2) / (2 * (1 ** 2))
y = 1 / (s * np.sqrt(2 * np.pi)) * np.exp(-a)
return x, y, x.mean(), x.std()
x = np.arange(-100, 100) # define range of x
x, y, u, s = normal(x, 10000)
plt.plot(x, y, label=r'$\mu=%.2f,\ \sigma=%.2f$' % (u, s))
plt.legend()
plt.savefig('graph/normal.png')
plt.show()
You can’t perform that action at this time.