xarray.core.rolling.DataArrayRolling.construct¶
-
DataArrayRolling.
construct
(window_dim=None, stride=1, fill_value=<NA>, **window_dim_kwargs)¶ Convert this rolling object to xr.DataArray, where the window dimension is stacked as a new dimension
- Parameters
window_dim (
str
or mapping, optional) – A mapping from dimension name to the new window dimension names. Just a string can be used for 1d-rolling.stride (
int
or mapping ofint
, optional) – Size of stride for the rolling window.fill_value (default:
dtypes.NA
) – Filling value to match the dimension size.**window_dim_kwargs (
{dim: new_name, ...}
, optional) – The keyword arguments form ofwindow_dim
.
- Returns
DataArray that is a view of the original array. The returned array is
not writeable.
Examples
>>> da = xr.DataArray(np.arange(8).reshape(2, 4), dims=("a", "b"))
>>> rolling = da.rolling(b=3) >>> rolling.construct("window_dim") <xarray.DataArray (a: 2, b: 4, window_dim: 3)> array([[[nan, nan, 0.], [nan, 0., 1.], [ 0., 1., 2.], [ 1., 2., 3.]], [[nan, nan, 4.], [nan, 4., 5.], [ 4., 5., 6.], [ 5., 6., 7.]]]) Dimensions without coordinates: a, b, window_dim
>>> rolling = da.rolling(b=3, center=True) >>> rolling.construct("window_dim") <xarray.DataArray (a: 2, b: 4, window_dim: 3)> array([[[nan, 0., 1.], [ 0., 1., 2.], [ 1., 2., 3.], [ 2., 3., nan]], [[nan, 4., 5.], [ 4., 5., 6.], [ 5., 6., 7.], [ 6., 7., nan]]]) Dimensions without coordinates: a, b, window_dim