在适当的条件下,相互独立的随机变量之和经适当标准化后,其分布近似于正态分布;不要求变量本身服从正态分布。
代码:
1 import random 2 import matplotlib.pyplot as plt 3 from statistics import mean 4 5 6 def sample(num_of_samples, sample_sz): 7 data = [] 8 for _ in range(num_of_samples): 9 data.append(mean([random.uniform(0.0, 1.0) for _ in range(sample_sz)])) 10 return data 11 12 13 if __name__ == "__main__": 14 15 data = sample(10000, 100) 16 plt.hist(data, bins = 'auto', rwidth = 0.8) 17 plt.axvline(x = mean(data), c = 'red') 18 plt.show()
只要样本数量足够大,样本均值就近似服从正态分布