πΎ Xarray is now 10 years old! π

xarray.Variable.rolling_window#

Variable.rolling_window(dim, window, window_dim, center=False, fill_value=<NA>)[source]#

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

Parameters:
• dim (str) β Dimension over which to compute rolling_window. For nd-rolling, should be list of dimensions.

• window (int) β Window size of the rolling For nd-rolling, should be list of integers.

• window_dim (str) β New name of the window dimension. For nd-rolling, should be list of strings.

• center (bool, default: False) β If True, pad fill_value for both ends. Otherwise, pad in the head of the axis.

• fill_value β value to be filled.

Returns:

• Variable that is a view of the original array with a added dimension of

• size w.

• The return dim (self.dims + (window_dim, ))

• The return shape (self.shape + (window, ))

Examples

>>> 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.]]])
>>> 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]]])