Normalizing data to certain range of values

user46543 picture user46543 · Jan 5, 2018 · Viewed 13.1k times · Source

I am a new in Python, is there any function that can do normalizing a data?

For example, I have set of list in range 0 - 1 example : [0.92323, 0.7232322, 0,93832, 0.4344433]

I want to normalize those all values to range 0.25 - 0.50

Thank you,

Answer

schwobaseggl picture schwobaseggl · Jan 5, 2018

You could do sth along the following lines:

>>> l = [0.92323, 0.7232322, 0.93832, 0.4344433]
>>> lower, upper = 0.25, 0.5
>>> l_norm = [lower + (upper - lower) * x for x in l]
>>> l_norm
[0.4808075, 0.43080805, 0.48458, 0.35861082499999997]