Return the cosine similarity betwee a brand's followers and the exemplars.

def cosine(brands, exemplars, weighted_avg=False, sqrt=False):
    """
    Return the cosine similarity betwee a brand's followers and the exemplars.
    """
    scores = {}
    for brand, followers in brands:
        if weighted_avg:
            scores[brand] = np.average([_cosine(followers, others) for others in exemplars.values()],
                                       weights=[1. / len(others) for others in exemplars.values()])
        else:
            scores[brand] = 1. * sum(_cosine(followers, others) for others in exemplars.values()) / len(exemplars)
    if sqrt:
        scores = dict([(b, math.sqrt(s)) for b, s in scores.items()])
    return scores