# xarray.computation.rolling.DataArrayRolling.construct

#### DataArrayRolling.construct(window_dim=None, \*, stride=1, fill_value=<NA>, keep_attrs=None, sliding_window_view_kwargs=None, \*\*window_dim_kwargs)[[source]](https://github.com/pydata/xarray/blob/main/xarray/computation/rolling.py#L371-L468)

Convert this rolling object to xr.DataArray,
where the window dimension is stacked as a new dimension

* **Parameters:**
  * **window_dim** (`Hashable` or [dict-like](https://docs.python.org/3/glossary.html#term-mapping) to `Hashable`, *optional*) – A mapping from dimension name to the new window dimension names.
  * **stride** ([`int`](https://docs.python.org/3/builtins/functions.html#int) or [mapping](https://docs.python.org/3/glossary.html#term-mapping) of [`int`](https://docs.python.org/3/builtins/functions.html#int), *default*: `1`) – Size of stride for the rolling window.
  * **fill_value** (*default*: `dtypes.NA`) – Filling value to match the dimension size.
  * **keep_attrs** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`None`](https://docs.python.org/3/builtins/constants.html#None)) – If True, the attributes (`attrs`) will be copied from the original
    object to the new one. If False, the new object will be returned
    without attributes. If None uses the global default.
  * **sliding_window_view_kwargs** (`Mapping`) – Keyword arguments that should be passed to the underlying array type’s
    `sliding_window_view` function.
  * **\*\*window_dim_kwargs** (`Hashable`, *optional*) – The keyword arguments form of `window_dim` {dim: new_name, …}.
* **Returns:**
  [`DataArray`](xarray.DataArray.html.md#xarray.DataArray) – a view of the original array. By default, the returned array is not writeable.
  For numpy arrays, one can pass `writeable=True` in `sliding_window_view_kwargs`.

#### SEE ALSO
[`numpy.lib.stride_tricks.sliding_window_view`](https://numpy.org/doc/stable/reference/generated/numpy.lib.stride_tricks.sliding_window_view.html#numpy.lib.stride_tricks.sliding_window_view), [`dask.array.lib.stride_tricks.sliding_window_view`](https://docs.dask.org/en/latest/generated/dask.array.lib.stride_tricks.sliding_window_view.html#dask.array.lib.stride_tricks.sliding_window_view)

### Notes

With dask arrays, it’s possible to pass the `automatic_rechunk` kwarg as
`sliding_window_view_kwargs={"automatic_rechunk": True}`. This controls
whether dask should automatically rechunk the output to avoid
exploding chunk sizes. Automatically rechunking is the default behaviour.
Importantly, each chunk will be a view of the data so large chunk sizes are
only safe if *no* copies are made later.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('c8d1e961-b0ee-4425-8329-9e00d3bdf1a6','5882ab85-08fe-4eaa-af13-f3df154fbd0a','ce2701c7-1c3e-4466-8776-509d46a05ce3','../lite/tree/../notebooks/index.html?path=c32600c0_8f67_4467_9860_ea18c649ab40.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> da = xr.DataArray(np.arange(8).reshape(2, 4), dims=("a", "b"))
```

```pycon
>>> rolling = da.rolling(b=3)
>>> rolling.construct("window_dim")
<xarray.DataArray (a: 2, b: 4, window_dim: 3)> Size: 192B
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
```

```pycon
>>> rolling = da.rolling(b=3, center=True)
>>> rolling.construct("window_dim")
<xarray.DataArray (a: 2, b: 4, window_dim: 3)> Size: 192B
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
```

<div id="ce2701c7-1c3e-4466-8776-509d46a05ce3" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('c8d1e961-b0ee-4425-8329-9e00d3bdf1a6','ce2701c7-1c3e-4466-8776-509d46a05ce3')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('c8d1e961-b0ee-4425-8329-9e00d3bdf1a6','ce2701c7-1c3e-4466-8776-509d46a05ce3')">Open In Tab</button></div><div id="5882ab85-08fe-4eaa-af13-f3df154fbd0a" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
