unpack#
- named_arrays.unpack(a, prototype, axis='pack')#
Reconstruct a structure from a flattened array and a prototype.
This is the inverse of
pack(). The flat values inaare distributed, in order, back onto the numeric leaves of a copy ofprototype, restoring each leaf’s units, axis names, and type from the prototype. Non-numeric parts of the structure are copied fromprototypeunchanged. Thusna.unpack(na.pack(a), a) == a.- Parameters:
a (AbstractScalarArray | ArrayLike) – The flattened values, for example the result of
pack()or thexreturned by ascipy.optimizeroutine.prototype (PrototypeT) – A structure with the same layout as the one that produced
a, supplying the units, axes, types, and traversal order used to rebuild it.axis (str) – The name of the logical axis of
aif it is a named array.
- Return type:
PrototypeT
See also
packFlatten the numeric leaves of a structure into a 1D array.
Examples
import numpy as np import astropy.units as u import named_arrays as na prototype = na.CartesianNdVectorArray({ "yaw": 0 * u.deg, "roll": 0 * u.deg, "defocus": 0 * u.mm, }) na.unpack(na.ScalarArray(np.array([1.0, 2.0, -3.0]), axes="pack"), prototype)
CartesianNdVectorArray(components={'yaw': <Quantity 1. deg>, 'roll': <Quantity 2. deg>, 'defocus': <Quantity -3. mm>})