grids.mixins.core.GridUtilsMixin.broadcast_array_to_axes#
- GridUtilsMixin.broadcast_array_to_axes(array: ndarray, axes_in: AxesInput, axes_out: AxesInput, **kwargs) ndarray [source]#
Reshape and broadcast an array aligned with axes_in so it is compatible with axes_out.
This utility is used to make field-like arrays broadcastable over a grid whose axes are specified by axes_out. It inserts singleton dimensions (1s) for any axes present in axes_out but not in axes_in, while preserving any trailing (non-grid) dimensions such as vector or tensor components.
- Parameters:
array (
np.ndarray
) – Input array. Its leading dimensions must correspond to the axes in axes_in. Any remaining dimensions (e.g., component indices) are preserved.axes_in (
str
orlist
ofstr
) – Axes that the leading dimensions of the array are aligned to.axes_out (
str
orlist
ofstr
) – Target axes to broadcast against. The returned array will have dimensions aligned with these axes.**kwargs – Any kwargs to pass to the array’s .reshape method.
- Returns:
A view or broadcasted copy of the input array, shaped to match axes_out and ready for operations over the target grid.
- Return type:
np.ndarray
- Raises:
ValueError – If axes_in is not a subset of axes_out, or if the array shape is incompatible with the specified input axes.