Search code examples
pythonmathremap

How can I remap list of numbers by changing its domain to a new target domain?


I have these numbers:

  1. 0.477486
  2. 0.627644
  3. 0.763021
  4. 0.857888
  5. 0.892062
  6. 0.857888
  7. 0.763021
  8. 0.627644
  9. 0.477486

    and I want to remap them to a new target domain for example 0 to 10 instead of 0.477486 to 0.892062.


Solution

  • You can use this method:

    >>> l = [0.477486, 0.627644, 0.763021, 0.857888, 0.892062,
             0.857888, 0.763021, 0.627644, 0.477486]
    >>> print([(i - min(l)) * 10 / (max(l) - min(l)) for i in l])
    

    This should print

    [0.0, 3.6219655744664423, 6.887398209254755, 9.17568793176643, 10.0, 9.17568793176643, 6.887398209254755, 3.6219655744664423, 0.0]