Masking in Dask

拟墨画扇 提交于 2019-12-11 02:35:18

问题


I was just wondering if someone could help show me how to apply functions such as "sum" or "mean" on masks arrays using dask. I wish to calculate the sum / mean of the array on only values where there is no mask.

Code:

import dask.array as da
import numpy as np
import numpy.ma as ma
dset = [1, 2, 3, 4] 
masked = ma.masked_equal(dset, (4)) # lets say 4 should be masked
print(np.sum(masked)) # output: 6
print(np.mean(masked)) # output: 2
print(masked) # output: [1, 2, 3, -]
masked_array = da.from_array(masked, chunks=(4))
print(masked_array.sum().compute(): # output: 10
print(masked_array.mean().compute()) # output: 2.5

Is there a way I can have my masked sum equal to np.sum(masked) and masked mean equal to 2 by ignoring the "4" value? It seems that numpy is able to ignore the "4" in its calculations but dask is not in this case.

来源:https://stackoverflow.com/questions/51195138/masking-in-dask

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!