数据归一化到指定区间,python代码如下:
import numpy as np
def normalize(x,a,b):
max_x=max(x)
min_x=min(x)
return a+(x-min_x)/(max_x-min_x)*(b-a)
if __name__=='__main__':
x=[1,2,1,1.5,3]
x=np.array(x)
normalize_x=normalize(x,0.1,0.5)
print('x:',x,'\n',
'normalize x:',normalize_x)