import math


def entropy(ps):
    """Calculates the entropy (log 2) of the distribution given by p
    """
    entropy = 0.0
    for p in ps:
        if not(p == 0):
            entropy -= p*math.log(p, 2)
    return entropy