Skip to content

how to understand name a record directly with name of a tuple? #1473

Discussion options

You must be logged in to vote

tuple keys in NumPy and Awkward usually refer to dimensions, e.g.

>>> import numpy as np
>>> matrix = np.identity(3)
>>> matrix[(0, 1)]
0

Awkward Array extends this to support another kind of structural feature: fields. Awkward Array let's you nest fields, e.g.

ak.count(x.y.z)

and this is the same as writing

ak.count(x[('y', 'z')])

Due to how indexing works, it's also the same if you didn't write any parentheses

ak.count(x['y', 'z'])

as Python constructs a tuple for the __getitem__ call.

So, to answer your question, events[("a", "b")] = ... is setting the field b of events.a (the RecordArray at field a) to a given value. You might think that you can just write

events.a.b = ...

But due to …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ZhenxuanZhang-Jensen
Comment options

@agoose77
Comment options

Answer selected by ZhenxuanZhang-Jensen
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