目标如题:我们将使用numpy中对随机数据矩阵进行归一化处理。
需要用到的知识点包括:
- random模块生成随机数矩阵
- 使用np的.mean函数和.std函数对数据进行归一化(数据-平均)/标准差 处理
- 使用axis参数指定按行计算
import numpy as np
import random
np_dat = np.random.randint(1,100,size=(3,4))
nm_dat = (np_dat - np_dat.mean(axis=0))/(np_dat.std(axis=0))
print(np_dat)
print(nm_dat)
输出结果如下:
[[ 1 92 70 25]
[99 54 87 6]
[33 38 1 1]]
[[-1.06201211 1.35411306 0.46611003 1.38637564]
[ 1.33976913 -0.32380965 0.9232564 -0.45137812]
[-0.27775701 -1.03030342 -1.38936643 -0.93499753]]
[Finished in 2.5s]