How to normalization data on numpy array, without MinMaxScaler package

Question:

how to normalize data without minmaxscaler package. here I have tried it according to the minmax scale formula. but i get an error like this IndexError: invalid index to scalar variable.

the code:

scale = []

for i in range(0,6):
    minFP = FCData[:,i].min()
    maxFP = FCData[:,i].max()
    yscale = (FCData[:,i] - minFP[i]) / ( maxFP[i] - minFP[i])
    scale.append(yscale[i])

scale = np.array(scale)

my data:
Data shape : (15000,6)

array([[     4.46733  ,      4.39629  ,    -34.2351   ,  -4077.23     ,
         -6206.81     ,   -874.539    ],
       [     7.65166  ,      2.61174  ,    -49.7356   ,  -4846.76     ,
         -9060.05     ,  -1291.39     ],
       [    11.285    ,     -2.91447  ,    -87.9661   ,  -5412.32     ,
        -16345.2      ,   -213.72     ],
       [    12.7313   ,     -6.48048  ,   -123.094    ,  -5939.48     ,
        -23005.6      ,    443.115    ],
       [    11.6425   ,      0.0259204,   -131.717    ,  -6972.53     ,
        -24651.9      ,  -1112.73     ],
       [    12.3602   ,     10.1988   ,   -139.597    ,  -8544.17     ,
        -26118.8      ,  -3260.79     ],
       [    16.0733   ,     12.1455   ,   -165.01     , -10371.5      ,
        -30873.5      ,  -3643.65     ],
       [    21.1933   ,      8.86926  ,   -210.599    , -12673.2      ,
        -39447.9      ,  -2785.69     ],
       [    24.3619   ,      7.59683  ,   -267.449    , -16170.6      ,
        -50300.9      ,  -2823.35     ]])

enter image description here

Asked By: stack offer

||

Answers:

You should be able to do this on 1 line with:

scaleddata = (FCData - FCData.min(axis=0)) / (FCData.max(axis=0) - FCData.min(axis=0))

or (thanks to @cards in the comments), this could be even shorter with:

scaleddata = (FCData - FCData.min(axis=0)) / np.ptp(FCData, axis=0)
Answered By: Matt Pitkin

maxFP and minFP are just values rather than lists/arrays, so do not need the i index, e.g., change yscale = (FCData[:,i] – minFP[i]) / ( maxFP[i] – minFP[i]) to yscale = (FCData[:,i] – minFP) / (maxFP – minFP) How to normalization data on numpy array, without MinMaxScaler package

Answered By: stack offer
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.