Skip to content

Using an index based predefined mask #792

Answered by jpivarski
williamnash asked this question in Q&A
Discussion options

You must be logged in to vote

As it turns out, it's easier than you think:

>>> gen_particles = ak.Array([["a", "b", "c"], ["a", "b", "c", "d", "e"], ["a", "b", "c"]])
>>> muon_gen_ids = ak.Array([[0, 1], [1, 3], [0]])
>>> gen_particles[muon_gen_ids]
<Array [['a', 'b'], ['b', 'd'], ['a']] type='3 * var * string'>

What you want is to use the ids as a slice. This is like NumPy's advanced indexing, but generalized to the non-rectilinear case.

(Thanks for the very clear example and desired result! It helped me understand your problem quickly.)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@williamnash
Comment options

Answer selected by williamnash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants