From 25c7cad3477d311daaf6b7587d33bf3e6c9b70a1 Mon Sep 17 00:00:00 2001 From: dcherian Date: Fri, 23 Mar 2018 09:52:25 -0700 Subject: [PATCH 1/3] Add weighted mean docs. Copied over from https://stackoverflow.com/questions/48510784/xarray-rolling-mean-with-weights --- doc/computation.rst | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/doc/computation.rst b/doc/computation.rst index 589df8eac36..ba0ec471070 100644 --- a/doc/computation.rst +++ b/doc/computation.rst @@ -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 @@ -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. +One can also use ``construct`` to compute a weighted 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. From 84486f5945b3bb64577998c11e9e69bb3a3c27e2 Mon Sep 17 00:00:00 2001 From: dcherian Date: Fri, 23 Mar 2018 13:37:12 -0700 Subject: [PATCH 2/3] fix voice --- doc/computation.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/computation.rst b/doc/computation.rst index ba0ec471070..6036e5d8c6c 100644 --- a/doc/computation.rst +++ b/doc/computation.rst @@ -185,7 +185,7 @@ 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. -One can also use ``construct`` to compute a weighted mean: +You can also use ``construct`` to compute a weighted mean: .. ipython:: python From 020138fe64b4e67f3bf0ef89d7cc9ce2fa179872 Mon Sep 17 00:00:00 2001 From: dcherian Date: Fri, 23 Mar 2018 14:44:20 -0700 Subject: [PATCH 3/3] fix --- doc/computation.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/computation.rst b/doc/computation.rst index 6036e5d8c6c..0f22a2ed967 100644 --- a/doc/computation.rst +++ b/doc/computation.rst @@ -185,7 +185,7 @@ 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 mean: +You can also use ``construct`` to compute a weighted rolling mean: .. ipython:: python