Skip to content

Awkward array of Lorentz Vectors from Awkward arrays of components #1342

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

You must be logged in to vote

The vector package provides a set of LorentzXXX classes, which exposes a suite of methods and properties relating specifically to Lorentz vectors.

vector can take existing arrays, and figure out which kind of array to return to you according to the fields that it has. For example, given your akarr:

>>> import awkward as ak
>>> import vector
>>> akarr = vector.zip({"px": [1,2,3], "py": [4,5,6], "pz": [7,8,9], "E": [10,11,12]})
>>> akarr
<MomentumArray4D [{x: 1, y: 4, z: 7, ... z: 9, t: 12}] type='3 * Momentum4D["x":...'>

Note that the array has more than just the Lorentz methods: it is a MomentumArray4D which pulls in lots of other classes:

>>> akarr.__class__.__mro__
(vector._backends.awk…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
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
2 participants