1. 程式人生 > >numpy數組-標準化數據

numpy數組-標準化數據

8.4 color clas iat 數組 via code nump RR

標準化數據的公式: (數據值 - 平均數) / 標準差

 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]

numpy數組-標準化數據