def flatten(repertoire, big_endian=False):
    """Flatten a repertoire, removing empty dimensions.

    By default, the flattened repertoire is returned in little-endian order.

    Args:
        repertoire (np.ndarray or None): A repertoire.

    Keyword Args:
        big_endian (boolean): If ``True``, flatten the repertoire in big-endian
            order.

    Returns:
        np.ndarray: The flattened repertoire.
    """
    if repertoire is None:
        return None
    order = 'C' if big_endian else 'F'
    return repertoire.squeeze().ravel(order=order)
