Skip to content

how to add new field in a 'zip' jagged array #2017

Discussion options

You must be logged in to vote

The syntax you are describing (muons.Muon['2pt'] = 2 * arrays['Muon_pt"]) is not quite right for assigning to an array. It also doesn't match up with the muons array that you've defined above, so I will assume it's a typing mistake?

If you have an array muons defined as

muons = ak.zip({
    "pt": arrays["Muon_pt"],
    "eta": arrays["Muon_eta"],
    "phi": arrays["Muon_phi"],
    "charge": arrays["Muon_charge"],
})

then you can assign a new/existing field with

muons['pt'] = ...

where ... is a Python expression.

This might fail if the expression cannot be broadcast against the existing array.

Replies: 1 comment 4 replies

Comment options

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

@ZhenxuanZhang-Jensen
Comment options

@agoose77
Comment options

@ZhenxuanZhang-Jensen
Comment options

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