def chi2(y, f, sigma, normalize=True):
    """
    Return the chi-square value for a series of measured values y and 
    uncertainties sigma that are described by model f.

                    y_i - f_i
    chi2 = sum_i( (-----------)^2 )
                     sigma_i

    Can be normalized by the number of entries.

    Inputs:
    -------
    y       :: np.array; values of the data which is to be described
    f       :: np.array; values predicted by the model
    sigma   :: np.array or float; uncertainties on values y
    normalize
            :: boolean; whether to divide the result by the length of y or not

    """
    res = sum(((y - f) / sigma) ** 2)
    res = res / len(y) if normalize else res
    return res
