0
$\begingroup$

If I have a vector of numbers $[-4,3,1,0.1,7]$, how do I scale this vector so that the smallest value becomes $-1$, the largest value becomes $1$, and the remaining numbers are adjusted so that the proportions are preserved?

1 Answers 1

1

The vector that you obtain is obviously not in the same direction in $R^k$ but you can do it this way: $$ v=2\cdot\frac{x-\rm{min}}{\rm{max}-\rm{min}}-1 $$ in this case: $$ v=2\cdot\frac{x+4}{11}-1 $$ now for all elements set $x$ to the value in your vector and $v$ is the new value you are seeking. if you want arbitrary limits $a\to b$: $$ v=(b-a)\cdot\frac{x-\rm{min}}{\rm{max}-\rm{min}}+a $$

  • 0
    What if I want to change the 'limits', so that it is no longer -1 and 1, but instead 50 and 150? Is it possible to adjust the function to this?2017-01-30
  • 0
    read now. and +1 if you are satisfied ;)2017-01-30
  • 0
    Great!! Thanks! The only problem is when $max=min$. What do I do about that?2017-01-30