numpy数组-标准化数据

标准化数据的公式: (数据值 - 平均数) / 标准差

 1 import numpy as np
 2 
 3 employment = np.array([
 4     55.70000076,  51.40000153,  50.5       ,  75.69999695,
 5     58.40000153,  40.09999847,  61.5       ,  57.09999847,
 6     60.90000153,  66.59999847,  60.40000153,  68.09999847,
 7     66.90000153,  53.40000153,  48.59999847,  56.79999924,
 8     71.59999847,  58.40000153,  70.40000153,  41.20000076
 9 ])
10 
11 mean = employment.mean()         #计算平均数
12 deviation = employment.std()     #计算标准差
13 # 标准化数据的公式: (数据值 - 平均数) / 标准差
14 standardized_employment = (employment - mean) / deviation  
15 print (standardized_employment)  

结果:

1   [-0.31965231 -0.780123   -0.87650077  1.82207181 -0.03051941 -1.99019768
2   0.30144772 -0.16973184  0.23719615  0.84758731  0.18365304  1.00821665
3   0.87971351 -0.56595055 -1.07996476 -0.20185762  1.38301845 -0.03051941
4   1.2545153  -1.87240259]

 

posted @ 2018-05-31 23:16  诗&远方  阅读(8182)  评论(0编辑  收藏  举报