def scale_feature(arr):
    """
        Rescales all values within array to be in range [0..1]
        When all values are identical: assign each new feature to 0.5 (halfway between 0.0 and 1.0)
    """
    xmin = min(arr)
    xmax = max(arr)
    res = []
    if xmin == xmax:
        res = [.5 for _ in arr]
    else:
        res = [float((x - xmin)) / (xmax - xmin) for x in arr]
    return res