Merging arrays in uproot4 #830
Unanswered
claudiopascoal
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Actually, this is an Awkward Array question, though I should start by saying that if you need to keep using Awkward 0/Uproot 3 for any reason, you can pip install awkward0 uproot3 and these packages can be imported into the same Python session with the new libraries. As for updating an array, there is this syntax: arrays["new_field_name"] = new_field and there's this, using ak.zip: new_arrays = ak.zip({"field1": field1, "field2": field2, ...}, depth_limit=1) Here's an example if you don't know or don't want to explicitly iterate over the fields using ak.unzip and ak.fields: >>> a = ak.Array([{"a": 1}, {"a": 2}, {"a": 3}])
>>> bc = ak.Array([{"b": 1, "c": 1}, {"b": 2, "c": 2}, {"b": 3, "c": 3}])
>>> ak.zip(dict(zip(ak.fields(a), ak.unzip(a)), **dict(zip(ak.fields(bc), ak.unzip(bc)))))
<Array [{a: 1, b: 1, c: 1}, ... b: 3, c: 3}] type='3 * {"a": int64, "b": int64, ...'> (New versions of Python have fancy syntax for merging dicts, but I'm using old syntax that's guaranteed to work.) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
My name is Cláudio, from the LZ collaboration.
i) I have two trees in which one is data and the second tree is Monte-Carlo.
ii) Then, from each tree I select only some branches and create a class 'awkward.highlevel.Array' in the following way:
arrays = tree1.arrays(variables)
iii) I would like to add Monte-Carlo branches to the arrays variables which contains data branches. Before, in uproot3, we could use:
arrays.update(tree2.arrays(mc_variables))
but this method is no longer available in uproot4.
What is the solution for this?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions