def _normalize_features(feature_list, prepared, is_traindata):
    """Normalize features (mean subtraction, division by variance or range).
    """
    if is_traindata:
        _calculate_feature_stats(feature_list,
                                 prepared,
                                 "featurenormalization.csv")

    start = 0
    for feature in feature_list:
        end = start + feature.get_dimension()
        # For every instance in the dataset: Normalize!
        for i in range(len(prepared)):
            # The 0 is necessary as every element is (x, y)
            feature_range = (feature.max - feature.min)
            if feature_range == 0:
                feature_range = 1
            prepared[i][0][start:end] = (prepared[i][0][start:end] -
                                         feature.mean) / feature_range
        start = end
    return prepared