def gini(k_proportions):
    """
    Gini impurity function. This is used to determine the impurity of a given
    set of data, given the proportions of the classes in the dataset.

    This is equivalent to:
    H = ∑ pk(1-pk) for all k classes.

    k_proportions, in this case, is an array of pk's

    :param k_proportions: array containing proportions of different classes. Proportions sum to 1.
    :return: the impurity of the dataset.
    """
    return (k_proportions*(1-k_proportions)).sum()