ak.unzip#
Defined in awkward.operations.ak_unzip on line 16.
- ak.unzip(array, *, how=tuple, highlevel=True, behavior=None, attrs=None)#
Splits records or tuples into a tuple or dict of arrays, one per field.
- Parameters:
array – Array-like data (anything
ak.to_layoutrecognizes).how (type) – The type of the returned output. This can be
tupleordict.highlevel (bool) – If True, return an
ak.Array; otherwise, return a low-levelak.contents.Contentsubclass.behavior (None or dict) – Custom
ak.behaviorfor the output array, if high-level.attrs (None or dict) – Custom attributes for the output array, if high-level.
- Returns:
If the
arraycontains tuples or records, this operation splits them into a Python tuple (or dict) of arrays, one for each field.If the
arraydoes not contain tuples or records, the singlearrayis placed in a length 1 Python tuple (or dict).
Examples
For example,
>>> array = ak.Array([{"x": 1.1, "y": [1]}, ... {"x": 2.2, "y": [2, 2]}, ... {"x": 3.3, "y": [3, 3, 3]}]) >>> x, y = ak.unzip(array) >>> x <Array [1.1, 2.2, 3.3] type='3 * float64'> >>> y <Array [[1], [2, 2], [3, 3, 3]] type='3 * var * int64'>
The
howargument determines the structure of the output. Usinghow=dictreturns a dictionary of arrays instead of a tuple, and let’s you round-trip throughak.zip:>>> array = ak.Array([{"x": 1.1, "y": [1]}, ... {"x": 2.2, "y": [2, 2]}, ... {"x": 3.3, "y": [3, 3, 3]}]) >>> x = ak.unzip(array, how=dict) >>> x {'x': <Array [1.1, 2.2, 3.3] type='3 * float64'>, 'y': <Array [[1], [2, 2], [3, 3, 3]] type='3 * var * int64'>} >>> assert ak.zip(ak.unzip(array, how=dict), depth_limit=1).to_list() == array.to_list() # True