Skip to content

Transpose a part of an Array #945

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

You must be logged in to vote

Given that you're using uproot, I believe you're obtaining arrays of the form

>>> arr = ak.Array([
...   { 'hit_x' : [ 0, 1, 0],
...     'hit_y' : [12, 0.3, 7],
...     'hit_z': [3, 8, 6]},
...
...   {'hit_x' : [ 1, 1],
...     'hit_y' : [3, 7],
...     'hit_z': [0,4]}
... ])

If you just wanted the records to have scalar fields, then one way to achieve what you want is to re-zip the array, i.e.

>>> fields = ak.unzip(arr)
>>> names = ak.fields(arr)
>>> rezipped = ak.zip(dict(zip(names, fields)))
>>> rezipped.tolist()
[[{'hit_x': 0, 'hit_y': 12.0, 'hit_z': 3},
  {'hit_x': 1, 'hit_y': 0.3, 'hit_z': 8},
  {'hit_x': 0, 'hit_y': 7.0, 'hit_z': 6}],
 [{'hit_x': 1, 'hit_y': 3.0, 'hit_z': 0},
  {'h…

Replies: 1 comment 3 replies

Comment options

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

@alpetukhov
Comment options

@jpivarski
Comment options

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