Alignment
xarray enforces alignment between index Coordinates (that is, coordinates with the same name as a dimension, marked by *
) on objects used in binary operations.
import xarray as xr
da = xr.open_dataarray("../data/air_temperature.nc")
da
arr = da.isel(time=0, lat=slice(5, 10), lon=slice(7, 11))
arr
part = arr[:-1]
part
- Default behavior is an
inner join
(arr + part) / 2
- We can also use an
outer join
with xr.set_options(arithmetic_join="outer"):
print((arr + part) / 2)
NOTE:
Notice that missing values (nan
) were inserted where it is appropriate.
%load_ext watermark
%watermark --iversion -g -m -v -u -d