如何规范化 python 中的 numpy 数组
how to normalize a numpy array in python
我有以下 numpy 数组:
from sklearn.decomposition import PCA
from sklearn.preprocessing import normalize
import numpy as np
# Tracking 4 associate metrics
# Open TA's, Open SR's, Open SE's
associateMetrics = np.array([[111, 28, 21],
[ 27, 17, 20],
[ 79, 23, 17],
[185, 125, 50],
[155, 76, 32],
[ 82, 24, 17],
[127, 63, 33],
[193, 91, 63],
[107, 24, 17]])
现在,我想对每个 'column' 进行归一化,使值介于 0 和 1 之间。我的意思是,例如,第一列中的值应该介于 0 和 1 之间。
我该怎么做?
normed_matrix = normalize(associateMetrics, axis=1, norm='l1')
上面给出了按行归一化
我能够使用以下方法做到这一点:
normalized_metrics = normalize(associateMetrics, axis=0, norm='l1')
我有以下 numpy 数组:
from sklearn.decomposition import PCA
from sklearn.preprocessing import normalize
import numpy as np
# Tracking 4 associate metrics
# Open TA's, Open SR's, Open SE's
associateMetrics = np.array([[111, 28, 21],
[ 27, 17, 20],
[ 79, 23, 17],
[185, 125, 50],
[155, 76, 32],
[ 82, 24, 17],
[127, 63, 33],
[193, 91, 63],
[107, 24, 17]])
现在,我想对每个 'column' 进行归一化,使值介于 0 和 1 之间。我的意思是,例如,第一列中的值应该介于 0 和 1 之间。
我该怎么做?
normed_matrix = normalize(associateMetrics, axis=1, norm='l1')
上面给出了按行归一化
我能够使用以下方法做到这一点:
normalized_metrics = normalize(associateMetrics, axis=0, norm='l1')