# xarray.Variable.rolling_window

#### Variable.rolling_window(dim, window, window_dim, \*, center=False, fill_value=<NA>, \*\*kwargs)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/variable.py#L2357-L2485)

Make a rolling_window along dim and add a new_dim to the last place.

* **Parameters:**
  * **dim** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Dimension over which to compute rolling_window.
    For nd-rolling, should be list of dimensions.
  * **window** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Window size of the rolling
    For nd-rolling, should be list of integers.
  * **window_dim** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – New name of the window dimension.
    For nd-rolling, should be list of strings.
  * **center** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`False`](https://docs.python.org/3/builtins/constants.html#False)) – If True, pad fill_value for both ends. Otherwise, pad in the head
    of the axis.
  * **fill_value** – value to be filled.
  * **\*\*kwargs** – Keyword arguments that should be passed to the underlying array type’s
    `sliding_window_view` function.
* **Returns:**
  * `Variable that is a view` of `the original array with an added dimension of`
  * `size w.`
  * **The return dim** (`self.dims + (window_dim`, `)`)
  * **The return shape** (`self.shape + (window`, `)`)

#### 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)

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('461f0711-d773-4f56-a747-923ced41da86','174d2e0f-76d7-424b-a4b6-c0ce958ef8cd','604af7ba-791f-4a12-82a8-b22f33536866','../lite/tree/../notebooks/index.html?path=ba283453_fbe4_4552_b14b_9a218112eff0.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> v = Variable(("a", "b"), np.arange(8).reshape((2, 4)))
>>> v.rolling_window("b", 3, "window_dim")
<xarray.Variable (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.]]])
```

```pycon
>>> v.rolling_window("b", 3, "window_dim", center=True)
<xarray.Variable (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]]])
```

<div id="604af7ba-791f-4a12-82a8-b22f33536866" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('461f0711-d773-4f56-a747-923ced41da86','604af7ba-791f-4a12-82a8-b22f33536866')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('461f0711-d773-4f56-a747-923ced41da86','604af7ba-791f-4a12-82a8-b22f33536866')">Open In Tab</button></div><div id="174d2e0f-76d7-424b-a4b6-c0ce958ef8cd" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
