Scale vector of numbers with right proportions

169 Views Asked by At

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

There are 1 best solutions below

3
On BEST ANSWER

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 $$