numpy 矩阵归一化
阅读原文时间:2023年07月10日阅读:2

new_value = (value - min)/(max-min)

def normalization(datingDatamat):
max_arr = datingDatamat.max(axis=0)
min_arr = datingDatamat.min(axis=0)
ranges = max_arr - min_arr
norDataSet = zeros(datingDatamat.shape)
m = datingDatamat.shape[0]
norDataSet = datingDatamat - np.tile(min_arr, (m, 1))
norDataSet = norDataSet/np.tile(ranges,(m,1))
return norDataSet