Skip to content

Changing shape based on rows with equal values #2664

Answered by agoose77
CaueSousa asked this question in Q&A
Discussion options

You must be logged in to vote

@jpivarski your answer is where my mind was going! I was unsure as to the requirement to split on both columns, but I accidentally found the solution :)

@CaueSousa I wasn't initially sure how easy this would be. It turns out that there's a neat trick (or at least, I think it's a trick!) that let's do this using run_lengths without any complex slicing.

First, let's define an example array

>>> array = ak.Array(
    [
        # A
        [0, 0, 1],
        [0, 0, 2],
        # B
        [1, 1, 3],
        # C
        [2, 2, 4],
        # D
        [2, 3, 5],
        [2, 3, 6],
    ]
)

Let's find the lengths of the "runs" of same-value items in the first column:

>>> runs_in_col_0 = ak.run_len…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@jpivarski
Comment options

@agoose77
Comment options

Answer selected by CaueSousa
@CaueSousa
Comment options

Comment options

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
3 participants