ak.to_packed#
Defined in awkward.operations.ak_to_packed on line 15.
- ak.to_packed(array, *, highlevel=True, behavior=None, attrs=None)#
- Parameters:
array – Array-like data (anything
ak.to_layoutrecognizes).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 an array with the same type and values as the input,
with all virtual buffers materialized (see ak.materialize) and inner structures packed:
ak.contents.NumpyArraybecomes C-contiguous (if it isn’t already)ak.contents.RegularArraytrims unreachable contentak.contents.ListArraybecomesak.contents.ListOffsetArray, making all list data contiguousak.contents.ListOffsetArraystarts atoffsets[0] == 0, trimming unreachable contentak.contents.RecordArraytrims unreachable contentsak.contents.IndexedArraygets projectedak.contents.IndexedOptionArrayremains anak.contents.IndexedOptionArray(with simplifiedindex) if it contains records, becomesak.contents.ByteMaskedArrayotherwiseak.contents.ByteMaskedArraybecomes anak.contents.IndexedOptionArrayif it contains records, stays aak.contents.ByteMaskedArrayotherwiseak.contents.BitMaskedArraybecomes anak.contents.IndexedOptionArrayif it contains records, stays aak.contents.BitMaskedArrayotherwiseak.contents.UnionArraygets projected contentsak.record.Recordbecomes a record over a single-itemak.contents.RecordArray
Example
>>> a = ak.Array([[1, 2, 3], [], [4, 5], [6], [7, 8, 9, 10]])
>>> b = a[::-1]
>>> b.layout
<ListArray len='5'>
<starts><Index dtype='int64' len='5'>
[6 5 3 3 0]
</Index></starts>
<stops><Index dtype='int64' len='5'>
[10 6 5 3 3]
</Index></stops>
<content><NumpyArray dtype='int64' len='10'>
[ 1 2 3 4 5 6 7 8 9 10]
</NumpyArray></content>
</ListArray>
>>> c = ak.to_packed(b)
>>> c.layout
<ListOffsetArray len='5'>
<offsets><Index dtype='int64' len='6'>[ 0 4 5 7 7 10]</Index></offsets>
<content><NumpyArray dtype='int64' len='10'>
[ 7 8 9 10 6 4 5 1 2 3]
</NumpyArray></content>
</ListOffsetArray>
Performing these operations will minimize the output size of data sent to
ak.to_buffers (though conversions through Arrow, ak.to_arrow and
ak.to_parquet, do not need this because packing is part of that conversion).
See also ak.to_buffers.