def normalize_features(y, method):
    """
    Normalize intensities or other features.

    Parameters
    ----------
    y : array(nsamples, nfeatures)
        Data matrix, e.g. raw spectra or decomposition components.
    method : str
        One of 'none', 'mean1', 'mean0', 'mean0var1'

    Returns
    -------
    Normalized data.
    """
    if method == 'none':
        return y
    elif method == 'mean1':
        means = y.mean(0)
        means[means == 0] = 1
        return y / means
    elif method == 'mean0':
        return y - y.mean(0)
    elif method == 'mean0var1':
        y = y - y.mean(0)
        sds = y.std(0)
        sds[sds == 0] = 1
        return y / sds
    raise ValueError('undefined normalization method ' + method)