def insert_offsets_and_prov_code(gct, offsets, offsets_field, prov_code, prov_code_field, prov_code_delimiter):
    """Insert offsets into output gct and update provenance code in metadata.

    Args:
        gct (GCToo object)
        offsets (numpy array of floats, or None): if optimization was not performed, this will be None
        offsets_field (string): name of col metadata field into which offsets will be inserted
        prov_code (list of strings)
        prov_code_field (string): name of col metadata field containing the provenance code
        prov_code_delimiter (string): what string to use as delimiter in prov_code

    Returns:
        gct (GCToo object): updated metadata

    """
    # Make sure that metadata and data dfs agree in shape
    assert gct.data_df.shape[0] == gct.row_metadata_df.shape[0]
    assert gct.data_df.shape[1] == gct.col_metadata_df.shape[0]

    # If offsets is not none, insert into col_metadata_df
    if offsets is not None:
        assert len(offsets) == gct.col_metadata_df.shape[0]
        gct.col_metadata_df[offsets_field] = offsets

    # Convert provenance code to delimiter separated string
    prov_code_str = prov_code_delimiter.join(prov_code)

    # Update the provenance code in col_metadata_df
    gct.col_metadata_df.loc[:, prov_code_field] = prov_code_str

    return gct