利用numpy求归一化
归一化公式为:
import numpy as np
x = np.array([[-1,2],[-0.5,6],[0,10],[1,18]])
print(x)
#归一化
x_nor = (x - x.min(axis=0))/(x.max(axis=0)-x.min(axis=0)) #(某个元素-它这列最小的数)/(它这列最大的数-它这列最小的数)
print(x_nor)
#逆转归一化
x_return = x_nor*(x.max(axis=0)-x.min(axis=0))+x.min(axis=0)
print(x_return)
[[-1. 2. ]
[-0.5 6. ]
[ 0. 10. ]
[ 1. 18. ]]
[[0. 0. ]
[0.25 0.25]
[0.5 0.5 ]
[1. 1. ]]
[[-1. 2. ]
[-0.5 6. ]
[ 0. 10. ]
[ 1. 18. ]]