def consolidate_bins(labels, n_bins_in, n_bins_out):
    """Consolidate bins.

    Args:
        labels (array): Input labels.
        n_bins_in (int): Number of bins for input data.
        n_bins_out (int): Number of desired output bins.

    Returns:
        array: Labels consolidated into the desired number of output
            bins.
    """
    assert n_bins_in % n_bins_out == 0, \
        (f"Must choose a number of output classes ({n_bins_out}) divisible by the"
         f"initial number of output classes ({n_bins_in}).")

    bin_consolidation_factor = n_bins_in / n_bins_out
    return labels // bin_consolidation_factor