-
(I have not really found a solution here but happy to update the issue otherwise) I have two awkward arrays, e.g. barrel electrons and endcap electrons -> the same objects with the same variables/fields.
I want to merge them such that for each row/event I get the concatenated list of objects, e.g.
Is there any built in method in awkward for this? p.s. I made the above examples by splitting a single array by a criterion ( |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
@artlbv - I think, you can get >>> barrel = ak.Array([[{"pt": 43.8, "eta": -0.532}, {"pt": 39.5, "eta": 0.271}], [{"pt": 11.5, "eta": 0.951}]])
>>> endcap = ak.Array([[], [{"pt": 68.8, "eta": 1.92}, {"pt": 38, "eta": 1.6}]])
>>> l1 = ak.to_layout(barrel.pt)
>>> l2 = ak.to_layout(endcap.pt)
>>> index = ak.index.Index64([0,1,0,1])
>>> tags = ak.index.Index8([np.int8(0),np.int8(0), np.int8(1),np.int8(1)])
>>> union = ak.contents.UnionArray(tags, index, contents={l1, l2})
>>> arr = ak.Array(union)
>>> arr
<Array [[43.8, 39.5], [11.5], ..., [68.8, 38]] type='4 * union[var * float6...'> |
Beta Was this translation helpful? Give feedback.
-
@artlbv I think what you're asking for is provided by import awkward as ak
barrel_eles = ak.from_iter([[{"pt": 43.8, "eta": -0.532}, {"pt": 39.5, "eta": 0.271}], [{"pt": 11.5, "eta": 0.951}]])
endcap_eles = ak.from_iter([[], [{"pt": 68.8, "eta": 1.92}, {"pt": 38, "eta": 1.6}]])
result = ak.concatenate((barrel_eles, endcap_eles), axis=1) Under the hood, this will build a union like @ianna demonstrates, but this union will be erased as both arrays |
Beta Was this translation helpful? Give feedback.
@artlbv I think what you're asking for is provided by
ak.concatenate
, with theaxis=1
argument:Under the hood, this will build a union like @ianna demonstrates, but this union will be erased as both arrays
barrel_eles
andendcap_eles
have mergeable (the same!) types.