Не надо л oop. Вы можете использовать numpy * std
и mean
, взятые вдоль первой оси:
(dataset-dataset.mean(0))/dataset.std(0)
array([[ 0.13736137, -0.39223227],
[-0.49430039, -0.39223227],
[ 0.50833732, -0.39223227],
[-0.72490707, -1.86310328],
[ 1.2603156 , 1.07863874],
[-0.01178099, 1.07863874],
[-0.577018 , -0.39223227],
[-0.7111208 , -0.39223227],
[-0.77002576, -0.39223227],
[-0.62714989, -0.39223227],
[-0.06817936, 1.07863874],
[ 0.00701846, -0.39223227],
[-0.13084422, -0.39223227],
[ 3.11268878, 2.54950976],
[-0.91039504, -0.39223227]])
Или вы также можете использовать StandardScaler
: 1010 *
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
scaler.fit_transform(dataset)
array([[ 0.13736137, -0.39223227],
[-0.49430039, -0.39223227],
[ 0.50833732, -0.39223227],
[-0.72490707, -1.86310328],
[ 1.2603156 , 1.07863874],
[-0.01178099, 1.07863874],
[-0.577018 , -0.39223227],
[-0.7111208 , -0.39223227],
[-0.77002576, -0.39223227],
[-0.62714989, -0.39223227],
[-0.06817936, 1.07863874],
[ 0.00701846, -0.39223227],
[-0.13084422, -0.39223227],
[ 3.11268878, 2.54950976],
[-0.91039504, -0.39223227]])