def create_long_form_weights(model_obj, wide_weights, rows_to_obs=None):
    """
    Converts an array of weights with one element per observation (wide-format)
    to an array of weights with one element per observation per available
    alternative (long-format).

    Parameters
    ----------
    model_obj : an instance or sublcass of the MNDC class.
        Should be the model object that corresponds to the model we are
        constructing the bootstrap confidence intervals for.
    wide_weights : 1D or 2D ndarray.
        Should contain one element or one column per observation in
        `model_obj.data`, depending on whether `wide_weights` is 1D or 2D
        respectively. These elements should be the weights for optimizing the
        model's objective function for estimation.
    rows_to_obs : 2D scipy sparse array.
        A mapping matrix of zeros and ones, were `rows_to_obs[i, j]` is one if
        row `i` of the long-format data belongs to observation `j` and zero
        otherwise.

    Returns
    -------
    long_weights : 1D or 2D ndarray.
        Should contain one element or one column per observation in
        `model_obj.data`, depending on whether `wide_weights` is 1D or 2D
        respectively. These elements should be the weights from `wide_weights`,
        simply mapping each observation's weight to the corresponding row in
        the long-format data.
    """
    # Ensure argument validity
    check_validity_of_long_form_args(model_obj, wide_weights, rows_to_obs)
    # Get a rows_to_obs mapping matrix.
    if rows_to_obs is None:
        rows_to_obs = model_obj.get_mappings_for_fit()['rows_to_obs']
    # Create a 2D version of
    wide_weights_2d =\
        wide_weights if wide_weights.ndim == 2 else wide_weights[:, None]
    long_weights = rows_to_obs.dot(wide_weights_2d)
    if wide_weights.ndim == 1:
        long_weights = long_weights.sum(axis=1)
    return long_weights
Converts an array of weights with one element per observation (wide-format)
    to an array of weights with one element per observation per available
    alternative (long-format).

    Parameters
    ----------
    model_obj : an instance or sublcass of the MNDC class.
        Should be the model object that corresponds to the model we are
        constructing the bootstrap confidence intervals for.
    wide_weights : 1D or 2D ndarray.
        Should contain one element or one column per observation in
        `model_obj.data`, depending on whether `wide_weights` is 1D or 2D
        respectively. These elements should be the weights for optimizing the
        model's objective function for estimation.
    rows_to_obs : 2D scipy sparse array.
        A mapping matrix of zeros and ones, were `rows_to_obs[i, j]` is one if
        row `i` of the long-format data belongs to observation `j` and zero
        otherwise.

    Returns
    -------
    long_weights : 1D or 2D ndarray.
        Should contain one element or one column per observation in
        `model_obj.data`, depending on whether `wide_weights` is 1D or 2D
        respectively. These elements should be the weights from `wide_weights`,
        simply mapping each observation's weight to the corresponding row in
        the long-format data.