[Python] How to use ak.Array with index arrays to create a custom masked output?

Discussão em 'Python' iniciado por Stack, Maio 28, 2025.

  1. Stack

    Stack Membro Participativo

    I have these arrays in Awkward Array:

    my_indices = ak.Array([[0,1],[0],[1]])
    my_dummy_arr = ak.Array([[1,1],[1,1],[1,1]])


    I want to generate this result:

    [[1,1],[1,0],[0,1]]


    Basically, for each sub-array, I want to keep 1 at the positions in my_indices and set 0 elsewhere, matching the structure of my_dummy_arr.

    How can I achieve this with Awkward Array? (Note that this is a dummy example and the actual data is much larger, so I do not want to use slow operations like python loops or list comprehension)

    Continue reading...

Compartilhe esta Página