python_reference/howtos_as_py_files/normalize_data.py

16 lines
442 B
Python
Raw Normal View History

2014-03-20 00:46:13 +00:00
# Sebastian Raschka, 03/2014
def normalize_val(x, data_list):
"""
Normalizes a value to a data list returning a float
between 0.0 and 1.0.
Returns the original object if value is not a integer or float.
"""
if isinstance(x, float) or isinstance(x, int):
numerator = x - min(data_list)
denominator = max(data_list) - min(data_list)
return numerator/denominator
else:
return x