一.代码实现
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 7 16:28:20 2018
@author: zhen
"""
# 最大值最小值归一化:(X-Xmin)/(Xmax-Xmin)
import numpy as np
import matplotlib.pyplot as plt
x = np.random.rand(100)
x = x.reshape(-1, 1)
rand = np.random.rand(100) * np.random.randint(10)
rand = rand.reshape(-1, 1)
# 获取Xmax,Xmin
x_max = np.max(rand)
x_min = np.min(rand)
result = []
# 查找数组的索引:np.where(rand == i)
for i in rand:
result.append((float(i[0]) - x_min)/(x_max - x_min))
result = np.array(result, dtype = float)
result = result.reshape(-1, 1)
# 可视化
plt.plot(x, rand, "r.", label="native")
plt.plot(x, result, "b.", linewidth=2, label="normalized")
plt.legend(loc="upper left")
plt.grid()
plt.show()
二.执行结果

红点表示归一化之前的原始数据,蓝点表示归一化后的数据!