cupy - 向前填充cupy / cudf
问题描述
应该可以用cupy/cudf执行填充吗?这个想法是执行一个施密特触发器函数,比如:
# pandas version
df = some_random_vector
on_off = (df>.3)*1 + (df<.3)*-1
on_off[on_off==0) = np.nan
on_off = on_off.fillna(method='ffill').fillna(0)
我正在尝试这个,但cupy没有积累ufunc:
def schmitt_trigger(x, th_lo, th_hi, initial = False):
on_off = ((x >= th_hi)*1 + (x <= th_lo)*-1).astype(cp.int8)
mask = (on_off==0)
idx = cp.where(~mask, cp.arange(start=0, stop=mask.shape[0], step=1), 0)
cp.maximum.accumulate(idx,axis=1, out=idx)
out = on_off[cp.arange(idx.shape[0])[:,None], idx]
return out
任何想法?谢谢!
解决方案
遗憾的是,RAPIDS 目前没有该功能,cudf
0.16 也可能没有。github中有功能请求。https://github.com/rapidsai/cudf/issues/1361
希望您能提出要求,以便开发人员知道它的高度需求。
至于施密特触发器,如果我有任何进展,我会研究它和你的代码并编辑这篇文章。
推荐阅读
- json - 在 JRXML 中使用 JSONQL 作为逗号分隔值的 Json 数组
- css - 在使用 ngb-datepicker 制作的日期范围内向开始和结束日期添加三角箭头
- python - 如何获得一个函数来存储一个新变量,并在它被传递后分配一个值
- c# - 连接尝试失败,因为连接方在 Azure 中经过一段时间后没有正确响应
- c++ - 在 C++ 中的第 n 次继承后停止从基类继承
- full-text-search - 在 Silverstripe 4 中启用全文搜索
- python - 当 python 退出终端关闭时,实例应该执行最终指令;这些不起作用
- angular - ngx-perfect-scrollbar 可以用于有角度的材质元素吗?
- javascript - 如何在设置本地存储之前设置预定义密钥?
- html - 导航菜单不显示