Xarray rolling mean with weights

前端 未结 3 599
执念已碎
执念已碎 2021-01-01 07:46

When I do running / rolling mean with weights in numpy, I e.g. do something like this:

data = np.random.random(100)  # Example data...
weights = np.array([1,         


        
3条回答
  •  爱一瞬间的悲伤
    2021-01-01 08:48

    This is specific for the [1,2,1] weights, and it requires two steps, so it is not the best solution, but it is quite quick:

    dim_name = "dim_0"
    da_mean = da.rolling(**{dim_name: 3, "center": True}).mean(dim=dim_name)
    da_mean = (3 * da_mean + da) / 4.  # Expand it, and add the middle value.
    

提交回复
热议问题