赞
踩
归一化,将矩阵规格化到0~1,即最小的变成0,最大的变成1,最小与最大之间的等比缩放。Z = np.random.random((5,5))
import numpy as np
Z = np.random.random((5,5))
print(Z)
max=Z.max()
min=Z.min()
print(max,min)
Z=(Z-min)/(max-min)
print(Z)
输出结果:
[[0.25303525 0.99681094 0.36594609 0.04002044 0.54792824]
[0.06921534 0.406925850.1957492 0.07253186 0.86404351]
[0.40006867 0.15025097 0.443783820.03820552 0.80692884]
[0.7702267 0.99836316 0.26948848 0.39156013 0.49678772]
[0.73695705 0.25479203 0.954615450.03215094 0.1828546 ]]
0.9983631554021115 0.03215093610347419
[[0.22860849 0.99839351 0.34546774 0.00814469 0.53381368]
[0.03836052 0.38788054 0.169319180.04179302 0.86098328]
[0.38078357 0.12222992 0.426027410.0062663 0.80187136]
[0.76388577 1. 0.24563707 0.37197748 0.48088482]
[0.72945271 0.2304267 0.95472247 0. 0.15597367]]
代码实现:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。