def normalize_mean_std(data, data_mean=None, data_std=None):
    """Normalizes the data by removing the mean and scaling the features to unit variance (or std).

    If data_mean or data_std are None, one or both of these values are computed from the given data.
    """
    if data_mean is None:
        data_mean = data.mean(axis=0)
    if data_std is None:
        data_std = data.std(axis=0)
    return (data - data_mean) / data_std