ak.to_packed — Awkward Array 2.8.2 documentation (original) (raw)
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_layout recognizes).
- highlevel (bool) – If True, return an ak.Array; otherwise, return a low-level ak.contents.Content subclass.
- behavior (None or dict) – Custom ak.behavior for 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, but with packed inner structures:
- ak.contents.NumpyArray becomes C-contiguous (if it isn’t already)
- ak.contents.RegularArray trims unreachable content
- ak.contents.ListArray becomes ak.contents.ListOffsetArray, making all list data contiguous
- ak.contents.ListOffsetArray starts at
offsets[0] == 0
, trimming unreachable content - ak.contents.RecordArray trims unreachable contents
- ak.contents.IndexedArray gets projected
- ak.contents.IndexedOptionArray remains an ak.contents.IndexedOptionArray (with simplified
index
) if it contains records, becomes ak.contents.ByteMaskedArray otherwise - ak.contents.ByteMaskedArray becomes an ak.contents.IndexedOptionArray if it contains records, stays a ak.contents.ByteMaskedArray otherwise
- ak.contents.BitMaskedArray becomes an ak.contents.IndexedOptionArray if it contains records, stays a ak.contents.BitMaskedArray otherwise
- ak.contents.UnionArray gets projected contents
- ak.record.Record becomes a record over a single-item ak.contents.RecordArray
Example
a = ak.Array([[1, 2, 3], [], [4, 5], [6], [7, 8, 9, 10]]) b = a[::-1] b.layout [6 5 3 3 0] [10 6 5 3 3] [ 1 2 3 4 5 6 7 8 9 10]
c = ak.to_packed(b) c.layout [ 0 4 5 7 7 10] [ 7 8 9 10 6 4 5 1 2 3]
Performing these operations will minimize the output size of data sent toak.to_buffers (though conversions through Arrow, ak.to_arrow andak.to_parquet, do not need this because packing is part of that conversion).
See also ak.to_buffers.