def zscore_normalize(arr, mask=None):
    """ Performs a batch Z-score normalization.

    Parameters
    ----------
    arr: array
        the input data.
    mask: array, default None
        the brain mask.

    Returns
    -------
    normalized: array
        the normalized input data.
    """
    if mask is not None:
        values = arr[mask == 1]
    else:
        values = arr
    mean = values.mean()
    std = values.std()
    return (arr - mean) / std