"normalizing" a value

Skip Montanaro skip.montanaro at gmail.com
Thu Jul 2 11:05:42 EDT 2015


This looks like a straightforward linear transformation issue to me
(like Fahrenheit to Celsius). Add 50 to all input values, giving you
values in the range 0 to 100. Then scale them into your 0 to 12 range
by multiplying them by 12/100:

>>> for n in range(-50, 50, 3):
...   print n, n + 50, (n + 50) * 12 / 100
...
-50 0 0.0
-47 3 0.36
-44 6 0.72
-41 9 1.08
-38 12 1.44
...
34 84 10.08
37 87 10.44
40 90 10.8
43 93 11.16
46 96 11.52
49 99 11.88

Did I misread your request in some way?

Skip



More information about the Python-list mailing list