Skip to content

Replacing metadata in rows #2954

Closed Answered by hyanwong
hyanwong asked this question in Q&A
Discussion options

You must be logged in to vote

The most efficient way to change multiple rows is probably to add them onto the end and then run the code in #2953:

import tskit
import numpy as np

def change_ragged_order(ragged_arr, ragged_offset, new_order):
    # returns a tuple of a new ragged_col in a new order and a new offset array
    ranges = np.array([ragged_offset[:-1], ragged_offset[1:]]).T
    new_ranges = ranges[new_order, :]
    idx = [np.arange(l, r, dtype=ragged_offset.dtype) for l, r in new_ranges if l != r]
    select = [] if len(idx) == 0 else np.concatenate(idx)
    return ragged_arr[select], np.insert(np.cumsum(np.diff(new_ranges, axis=1)), 0, 0)

def change_metadata(new_md_dict, table):
    if table.metadata_schema.

Replies: 2 comments

Comment options

hyanwong
May 29, 2024
Maintainer Author

You must be logged in to vote
0 replies
Answer selected by hyanwong
Comment options

hyanwong
Jul 13, 2024
Maintainer Author

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant