Skip to content

How to delete some events (know the index) in analysis using awkward?? #1714

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

You must be logged in to vote

Finding where sublists have a particular length

Before we look at removing the rows (sublists) that have lengths different from four, let's first find where those sublists are. Then we can ask Awkward Array to remove them.

Consider an example list particle_x:

>>> particle_x = ak.Array([
    [1.0, 2.0, 3.0, 4.0],
    [5.0, 6.0],
    []
])
>>> particle_x
<Array [[1, 2, 3, 4], [5, 6], []] type='3 * var * float64'>

First of all, let's measure the length of each sublist in particle_x. If I compute ak.num(particle_x, axis=-1), Awkward will return a list of integers that corresponds to the lengths of these sublists:

>>> n_particles = ak.num(particle_x, axis=-1)
>>> n_particles
<Array [4, 2, 0] type

Replies: 1 comment 1 reply

Comment options

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

Answer selected by shaoweisong
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