Scaling range of values with negative numbers
Posted
by
Pradeep Kumar
on Stack Overflow
See other posts from Stack Overflow
or by Pradeep Kumar
Published on 2012-10-30T10:46:15Z
Indexed on
2012/10/30
11:01 UTC
Read the original article
Hit count: 162
How can I scale a set of values to fit a new range if they include negative numbers?
For example, I have a set of numbers (-10, -9, 1, 4, 10) which have to scaled to a range [0 1], such that -10 maps to 0, and 10 maps to 1.
The regular method for an arbitrary number 'x' would be: (x - from_min) * (to_max - to_min) / (from_max - from_min) + to_min
but this does not work for negative numbers. Any help is appreciated. Thanks!!
© Stack Overflow or respective owner