ak.packed
Defined in awkward.operations.structure on line 2450.
- ak.packed(array, highlevel=True, behavior=None)
- Parameters:
array – Array whose internal structure will be packed.
highlevel (bool) – If True, return an
ak.Array; otherwise, return a low-levelak.layout.Contentsubclass.behavior (None or dict) – Custom
ak.behaviorfor the output array, if high-level.
Returns an array with the same data as the input, but with packed inner structures:
ak.layout.NumpyArraybecomes C-contiguous (if it isn’t already)ak.layout.RegularArraytrims unreachable contentak.layout.ListArraybecomesak.layout.ListOffsetArray, making all list data contiguousak.layout.ListOffsetArraystarts atoffsets[0] == 0, trimming unreachable contentak.layout.RecordArraytrims unreachable contentsak.layout.IndexedArraygets projectedak.layout.IndexedOptionArrayremains anak.layout.IndexedOptionArray(with simplifiedindex) if it contains records, becomesak.layout.ByteMaskedArrayotherwiseak.layout.ByteMaskedArraybecomes anak.layout.IndexedOptionArrayif it contains records, stays aak.layout.ByteMaskedArrayotherwiseak.layout.BitMaskedArraybecomes anak.layout.IndexedOptionArrayif it contains records, stays aak.layout.BitMaskedArrayotherwiseak.layout.UnionArraygets projected contentsak.layout.VirtualArraygets materializedak.layout.Recordbecomes a record over a single-itemak.layout.RecordArray
Example
>>> a = ak.Array([[1, 2, 3], [], [4, 5], [6], [7, 8, 9, 10]])
>>> b = a[::-1]
>>> b
<Array [[7, 8, 9, 10], [6, ... [], [1, 2, 3]] type='5 * var * int64'>
>>> b.layout
<ListArray64>
<starts><Index64 i="[6 5 3 3 0]" offset="0" length="5" at="0x55e091c2b1f0"/></starts>
<stops><Index64 i="[10 6 5 3 3]" offset="0" length="5" at="0x55e091a6ce80"/></stops>
<content><NumpyArray format="l" shape="10" data="1 2 3 4 5 6 7 8 9 10" at="0x55e091c47260"/></content>
</ListArray64>
>>> c = ak.packed(b)
>>> c
<Array [[7, 8, 9, 10], [6, ... [], [1, 2, 3]] type='5 * var * int64'>
>>> c.layout
<ListOffsetArray64>
<offsets><Index64 i="[0 4 5 7 7 10]" offset="0" length="6" at="0x55e091b077a0"/></offsets>
<content><NumpyArray format="l" shape="10" data="7 8 9 10 6 4 5 1 2 3" at="0x55e091d04d30"/></content>
</ListOffsetArray64>
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.