xdas.align#
- xdas.align(*objs)[source]#
Given any number of data arrays, returns new objects with aligned dimensions.
New objects will all share the same dimensions with the same order. This is done by expanding missing dimensions and transposing to the same dims. The order of the resulting dims is given by the order in which dimensions are first encountered while iterating through each objects dims. For each dimensions, the data arrays must either share the same coordinate or not having any.
Array from the aligned objects are suitable as input to mathematical operators, as their shapes are compatible in term of broadcasting.
- Parameters:
*objects (DataArray) – Data arrays to align.
- Returns:
aligned – Tuple of data arrays with aligned coordinates.
- Return type:
Examples
>>> import xdas as xd >>> import numpy as np
>>> da1 = xd.DataArray(np.arange(2), {"x": [0, 1]}) >>> da2 = xd.DataArray(np.arange(3), {"y": [2, 3, 4]}) >>> da1, da2 = xd.align(da1, da2) >>> da1 <xdas.DataArray (x: 2, y: 1)> [[0] [1]] Coordinates: * x (x): [0 1] Dimensions without coordinates: y
>>> da2 <xdas.DataArray (x: 1, y: 3)> [[0 1 2]] Coordinates: * y (y): [2 ... 4] Dimensions without coordinates: x