Skip to content

Commit 7c2c43c

Browse files
dcherianmax-sixty
authored andcommitted
Add weighted mean docs. (#2012)
* Add weighted mean docs. Copied over from https://stackoverflow.com/questions/48510784/xarray-rolling-mean-with-weights * fix voice * fix
1 parent 9261601 commit 7c2c43c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

doc/computation.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ We can also manually iterate through ``Rolling`` objects:
170170
for label, arr_window in r:
171171
# arr_window is a view of x
172172
173-
Finally, the rolling object has ``construct`` method, which gives a
174-
view of the original ``DataArray`` with the windowed dimension attached to
173+
Finally, the rolling object has a ``construct`` method which returns a
174+
view of the original ``DataArray`` with the windowed dimension in
175175
the last position.
176-
You can use this for more advanced rolling operations, such as strided rolling,
177-
windowed rolling, convolution, short-time FFT, etc.
176+
You can use this for more advanced rolling operations such as strided rolling,
177+
windowed rolling, convolution, short-time FFT etc.
178178

179179
.. ipython:: python
180180
@@ -185,6 +185,12 @@ windowed rolling, convolution, short-time FFT, etc.
185185
186186
Because the ``DataArray`` given by ``r.construct('window_dim')`` is a view
187187
of the original array, it is memory efficient.
188+
You can also use ``construct`` to compute a weighted rolling mean:
189+
190+
.. ipython:: python
191+
192+
weight = xr.DataArray([0.25, 0.5, 0.25], dims=['window'])
193+
arr.rolling(y=3).construct('window').dot(weight)
188194
189195
.. note::
190196
numpy's Nan-aggregation functions such as ``nansum`` copy the original array.

0 commit comments

Comments
 (0)