3
$\begingroup$

How can I normalize an array of values (e.g., {0, 3, 4, 7, 9, 13, 22}) to a range of [12, 24]?

$\endgroup$
2
  • $\begingroup$ Perhaps 12 $+$ 12 $\times$ value / (max $-$ min) is what you seek. $\endgroup$
    – Nick Cox
    Commented Jun 16, 2018 at 16:27
  • 1
    $\begingroup$ @NickCox, why not make that an official answer? I'm not sure there's anything else to say here... $\endgroup$ Commented Jun 16, 2018 at 16:52

1 Answer 1

10
$\begingroup$

@NickCox already provided an answer in the comments, I will only elaborate on it step-by-step and try to provide some intuition.

You have a range on numbers ranging from $x$ to $y$ and you want to transform it into some interval $x_{new}$ to $y_{new}$.

You can think about this in three steps:

  • 1st transform the numbers to have a range from 0 to $z$.
  • 2nd transform the range 0 to $z$ into a range 0 to 1.
  • 3rd transform the range 0 to 1 to $x_{new}$ to $y_{new}$.

1st step

Subtract the minimum value from each number in your array. This will force the minimum to become 0. Note that it works even if your data has negative numbers! If your minimum number is -10 after subtracting -10 it will become 0 and all the others will be higher than 0.

2nd step

Now your numbers have a range of 0 to some positive number $z$. 2nd step is dividing all the numbers by $z$. Since the maximum number is $z$ - when you divide it by $z$ it will become 1. And your minimum number is 0 and when you divide 0 it will remain 0. So after this procedure all your numbers will be in a range of 0 to 1.

3rd step

We are transforming to a range from $x_{new}$ to $y_{new}$. This will involve two steps: First is to transform the range we have now (0 : 1) to (0 : ($y_{new} - x_{new}))$. And then we will add $x_{new}$ to obtain the final result of $x_{new}$ to $y_{new}$

Example

Let's transform your numbers ${0, 3, 4, 7, 9, 13, 22}$ to a range $12-24$.

First we see that the minimum number is $0$. We subtract $0$ from every number and we get the same numbers as a result.

Second - the maximum is $22$ - so we divide every number by $22$ and we get these numbers: $${0.00, 0.14, 0.18, 0.32, 0.40, 0.59, 1.00}$$

Third - we transform them at first to a range of $0-12$ (the idea is that after this we add $12$ and we get a range $12-24$). To do that - we multiply every number by $12$. And we get these numbers: $${0.00, 1.64, 2.18, 3.82, 4.91, 7.09, 12.00}$$

Finally we add 12 to all the numbers and the final result is:

$${12.00, 13.64, 14.18, 15.82, 16.91, 19.09, 24.00}$$

$\endgroup$
3
  • $\begingroup$ may I ask what's the name of this process? Does it have an official name ? $\endgroup$
    – AL-zami
    Commented Nov 10, 2019 at 15:47
  • 2
    $\begingroup$ Not too sure if it has an official name, and more - the name might depend on the field. The two most common names are "min-max scaling" and "unity based normalization". $\endgroup$ Commented Nov 10, 2019 at 19:38
  • 1
    $\begingroup$ Ok thanks. I have searched google and found out that It is called min-max normalization. $\endgroup$
    – AL-zami
    Commented Nov 11, 2019 at 5:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.