xarray.DataArray.broadcast_like¶
-
DataArray.
broadcast_like
(self, other: Union[ForwardRef('DataArray'), xarray.core.dataset.Dataset], exclude: Iterable[Hashable] = None) → 'DataArray'¶ Broadcast this DataArray against another Dataset or DataArray.
This is equivalent to xr.broadcast(other, self)[1]
xarray objects are broadcast against each other in arithmetic operations, so this method is not be necessary for most uses.
If no change is needed, the input data is returned to the output without being copied.
If new coords are added by the broadcast, their values are NaN filled.
- Parameters
- Returns
new_da
- Return type
xr.DataArray
Examples
>>> arr1 <xarray.DataArray (x: 2, y: 3)> array([[0.840235, 0.215216, 0.77917 ], [0.726351, 0.543824, 0.875115]]) Coordinates: * x (x) <U1 'a' 'b' * y (y) <U1 'a' 'b' 'c' >>> arr2 <xarray.DataArray (x: 3, y: 2)> array([[0.612611, 0.125753], [0.853181, 0.948818], [0.180885, 0.33363 ]]) Coordinates: * x (x) <U1 'a' 'b' 'c' * y (y) <U1 'a' 'b' >>> arr1.broadcast_like(arr2) <xarray.DataArray (x: 3, y: 3)> array([[0.840235, 0.215216, 0.77917 ], [0.726351, 0.543824, 0.875115], [ nan, nan, nan]]) Coordinates: * x (x) object 'a' 'b' 'c' * y (y) object 'a' 'b' 'c'