Skip to main content
 首页 » 编程设计

python之R 的 `filter` 的 NumPy 模拟

2024年10月25日10tintown

什么是R的模拟filter在 NumPy 中?

我有以下 R 代码:

f <- rep(1/9, 9) 
smth_x <- filter(x, f, sides=2) 

其中 x 是一些可能包含 nan 的一维时间序列向量。

如何使用 NumPy 执行相同的操作? (或任何其他 python 库)

请您参考如下方法:

我认为 scipy filter functions做你想做的,特别是lfilter .来自 this HOWTO :

import numpy, scipy.signal 
taps = numpy.repeat(1.0/9, 9) 
smoothed_x = scipy.signal.lfilter(taps, 1.0, x)