In [2]:
import numpy as np
import pandas as pd
import xarray as xr

In [3]:
arr = xr.DataArray(np.arange(0, 7.5, 0.5).reshape(3, 5),dims=('x', 'y'))

In [4]:
arr


Out[4]:
<xarray.DataArray (x: 3, y: 5)>
array([[ 0. ,  0.5,  1. ,  1.5,  2. ],
       [ 2.5,  3. ,  3.5,  4. ,  4.5],
       [ 5. ,  5.5,  6. ,  6.5,  7. ]])
Coordinates:
  * x        (x) int64 0 1 2
  * y        (y) int64 0 1 2 3 4

In [22]:
r = arr.rolling(y=3)

In [23]:
r


Out[23]:
DataArrayRolling [window->3,center->False,dim->y]

In [28]:
for label, arr_window in r:
    print("======label")
    print(label)
    print("======arr_window")
    print(arr_window)


======label
<xarray.DataArray 'y' ()>
array(0, dtype=int64)
Coordinates:
    y        int64 0
======arr_window
<xarray.DataArray (x: 3, y: 1)>
array([[ nan],
       [ nan],
       [ nan]])
Coordinates:
  * x        (x) int64 0 1 2
  * y        (y) int64 0
======label
<xarray.DataArray 'y' ()>
array(1, dtype=int64)
Coordinates:
    y        int64 1
======arr_window
<xarray.DataArray (x: 3, y: 2)>
array([[ nan,  nan],
       [ nan,  nan],
       [ nan,  nan]])
Coordinates:
  * x        (x) int64 0 1 2
  * y        (y) int64 0 1
======label
<xarray.DataArray 'y' ()>
array(2, dtype=int64)
Coordinates:
    y        int64 2
======arr_window
<xarray.DataArray (x: 3, y: 3)>
array([[ 0. ,  0.5,  1. ],
       [ 2.5,  3. ,  3.5],
       [ 5. ,  5.5,  6. ]])
Coordinates:
  * x        (x) int64 0 1 2
  * y        (y) int64 0 1 2
======label
<xarray.DataArray 'y' ()>
array(3, dtype=int64)
Coordinates:
    y        int64 3
======arr_window
<xarray.DataArray (x: 3, y: 3)>
array([[ 0.5,  1. ,  1.5],
       [ 3. ,  3.5,  4. ],
       [ 5.5,  6. ,  6.5]])
Coordinates:
  * x        (x) int64 0 1 2
  * y        (y) int64 1 2 3
======label
<xarray.DataArray 'y' ()>
array(4, dtype=int64)
Coordinates:
    y        int64 4
======arr_window
<xarray.DataArray (x: 3, y: 3)>
array([[ 1. ,  1.5,  2. ],
       [ 3.5,  4. ,  4.5],
       [ 6. ,  6.5,  7. ]])
Coordinates:
  * x        (x) int64 0 1 2
  * y        (y) int64 2 3 4

In [ ]: