def norm(distribution):
    """Normalize array 'distribution', so that its entries
    add up to 1.0."""
    S = sum(distribution)
    if  S <= 0.0:
        # raise ValueError, "Cannot normalize empty distribution!"
        return distribution # do nothing
    return distribution / S