Skip to content

Add weighted mean docs. #2012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions doc/computation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ We can also manually iterate through ``Rolling`` objects:
for label, arr_window in r:
# arr_window is a view of x

Finally, the rolling object has ``construct`` method, which gives a
view of the original ``DataArray`` with the windowed dimension attached to
Finally, the rolling object has a ``construct`` method which returns a
view of the original ``DataArray`` with the windowed dimension in
the last position.
You can use this for more advanced rolling operations, such as strided rolling,
windowed rolling, convolution, short-time FFT, etc.
You can use this for more advanced rolling operations such as strided rolling,
windowed rolling, convolution, short-time FFT etc.

.. ipython:: python

Expand All @@ -185,6 +185,12 @@ windowed rolling, convolution, short-time FFT, etc.

Because the ``DataArray`` given by ``r.construct('window_dim')`` is a view
of the original array, it is memory efficient.
You can also use ``construct`` to compute a weighted rolling mean:

.. ipython:: python

weight = xr.DataArray([0.25, 0.5, 0.25], dims=['window'])
arr.rolling(y=3).construct('window').dot(weight)

.. note::
numpy's Nan-aggregation functions such as ``nansum`` copy the original array.
Expand Down