def scale_features(X, approach='standard'):
    """Scale feature matrix.

    Parameters
    ----------
    X : torch.Tensor
        Tensor of shape (n_samples, n_channels, lookback, n_assets). Unscaled

    approach : str, {'standard', 'percent'}
        How to scale features.

    Returns
    -------
    X_scaled : torch.tensor
        Tensor of shape (n_samples, n_channels, lookback, n_assets). Scaled.
    """
    n_samples, n_channels, lookback, n_assets = X.shape

    if approach == 'standard':
        means = X.mean(dim=[2, 3])  # for each sample and each channel a mean is computed (over lookback and assets)
        stds = X.std(dim=[2, 3]) + 1e-6  # for each sample and each channel a std is computed (over lookback and assets)

        means_rep = means.view(n_samples, n_channels, 1, 1).repeat(1, 1, lookback, n_assets)
        stds_rep = stds.view(n_samples, n_channels, 1, 1).repeat(1, 1, lookback, n_assets)

        X_scaled = (X - means_rep) / stds_rep

    elif approach == 'percent':
        X_scaled = X * 100

    else:
        raise ValueError('Invalid scaling approach {}'.format(approach))

    return X_scaled