Skip to content

Rolling Std along axis #5415

Answered by max-sixty
babameme asked this question in Q&A
Jun 1, 2021 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

Thanks for writing out the example @babameme .

There may be a creative way to do this, but there isn't a multi-d rolling aggregation in xarray. The best I've come up with is this workaround: (Edit: this is wrong!! See @dcherian 's answer below)

In [21]: X.stack(z=['X','Y']).rolling(z=3*4).std()[::4]
Out[21]:
<xarray.DataArray (z: 12)>
array([       nan,        nan,        nan, 3.45205253, 3.45205253,
       3.45205253, 3.45205253, 3.45205253, 3.45205253, 3.45205253,
       3.45205253, 3.45205253])
Coordinates:
  * z        (z) MultiIndex
  - X        (z) int64 0 1 2 3 4 5 6 7 8 9 10 11
  - Y        (z) int64 0 0 0 0 0 0 0 0 0 0 0 0

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@dcherian
Comment options

@max-sixty
Comment options

@dcherian
Comment options

Answer selected by max-sixty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
3 participants