def weighted_mean(counts, weights=None):
    """The mean of the input counts.  If weights are provided, returns the weighted mean."""
    if weights is None:
        return counts.mean()

    return (counts * weights).sum() / weights.sum()