Skip to content

Instantly share code, notes, and snippets.

@jrjames83
Created February 1, 2018 03:55
Show Gist options
  • Save jrjames83/e37bba221e4de5689aa8dc6f82012548 to your computer and use it in GitHub Desktop.
Save jrjames83/e37bba221e4de5689aa8dc6f82012548 to your computer and use it in GitHub Desktop.
Python Central Limit Theorem
import numpy as np
import random
# Create a parent distribution, from the gamma family
shape, scale = 2., 2. # mean=4, std=2*sqrt(2)
s = np.random.gamma(shape, scale, 100000)
print(np.mean(s))
import matplotlib.pyplot as plt
import scipy.special as sps
plt.hist(s)
plt.show()
# The distribution of the means from the sampled groups is normally distributed
samples = [ np.mean(random.choices(s, k=20)) for _ in range(1000) ]
plt.hist(samples)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment