(1) # coding: utf-8
(2) import numpy as np
(3) Adult_group = np.array([177, 169, 171, 171, 173, 175, 170, 173, 169, 172, 173, 175,
179, 176, 166, 170, 167, 171, 171, 169])
(4) Children_group = np.array([72, 76, 72, 70, 69, 76, 77, 72, 6 8, 74, 72, 70, 71, 73,
75, 71, 72, 72, 71, 67])
(5) print (u' 成人组标准差:%.2f 幼儿组标准差:%.2f'
(6) % (np.std(Adult_group, ddof=1), np.std(Children_group, ddof=1)))
(7) print (u' 成人组均值:%.2f 幼儿组均值:%.2f'
(8) % (np.mean(Adult_group), np.mean(Children_group)))
(9) print (u' 成人组离散系数:%.4f 幼儿组离散系数:
%.4f'
(10) % ((np.std(Adult_group, ddof=1) / np.mean(Adult_group), np.std(Children_
group, ddof=1) / np.mean(Children_group))))
(1) # coding: utf-8
(2) import numpy as np
(3) import matplotlib.pyplot as plt
(4) import scipy.stats as sts
(5) plt.rcParams['font.sans-serif']=['SimHei']
(6) plt.rcParams['axes.unicode_minus']=False
(7) samples = np.around(np.random.normal(loc=0.0, scale=1.0, size=580000),2)
(8) plt.figure(num=1,dpi=300)
(9) plt.ylabel(u' 频数', size=14)
(10) plt.hist(samples, bins=1300, range=(-5,5))
(11) n_mean=np.round(np.mean(samples),2)
(12) n_median=np.round(np.median(samples),2)
(13) n_mode=sts.mode(samples)
(14) n_Skewness,n_kurtosis=sts.describe(samples)[4:]
(15) plt.text(-5,2100,u'均值:%.2f;中位数:%.2f; 众数:%.2f' %(n_mean, n_median, n_mode.mode) ,
size=8)
(16) plt.text(-5,2000,u'偏度:%.4f; 峰度:%.4f' %(n_Skewness,n_kurtosis), size=8)
(17) plt.show()
(1) import numpy as np
(2) import matplotlib
(3) import matplotlib.pyplot as plt
(4) np.random.seed(1)
(5) x = np.random.randint(0, 100, 50)
(6) y1 = 0.8*x + np.random.normal(0, 15, 50)
(7) y2 = 100 - 0.7*x + np.random.normal(0, 15, 50)
(8) y3 = np.random.randint(0, 100, 50)
(9) r1=np.corrcoef(x, y1)
(10) r2=np.corrcoef(x, y2)
(11) r3=np.corrcoef(x, y3)
(12) fig = plt.figure()
(13) plt.subplot(131)
(14) plt.scatter(x, y1,color='k')
(15) plt.subplot(132)
(16) plt.scatter(x, y2,color='k')
(17) plt.subplot(133)
(18) plt.scatter(x, y3,color='k')
(19) print r1
(20) print r2
(21) print r3
(22) plt.show()