python - How to normalize a list of positive and negative decimal number to a specific range -
i have list of decimal numbers follows:
[-23.5, -12.7, -20.6, -11.3, -9.2, -4.5, 2, 8, 11, 15, 17, 21]
i need normalize list fit range [-5,5]
.
how can in python?
to range of input easy:
old_min = min(input) old_range = max(input) - old_min
here's tricky part. can multiply new range , divide old range, guarantees top bucket 1 value in it. need expand output range top bucket same size other buckets.
new_min = -5 new_range = 5 + 0.9999999999 - new_min output = [int((n - old_min) / old_range * new_range + new_min) n in input]
Comments
Post a Comment