def rankhist_compute(rankhist, normalize=True):
    """Return the rank histogram counts and optionally normalize the histogram.

    Parameters
    ----------
    rankhist : dict
        A rank histogram object created with rankhist_init.
    normalize : bool
        If True, normalize the rank histogram so that the bin counts sum to one.

    Returns
    -------
    out : array_like
        The counts for the n+1 bins in the rank histogram, where n is the number
        of ensemble members.

    """
    if normalize:
        return 1.0*rankhist["n"] / sum(rankhist["n"])
    else:
        return rankhist["n"]