R的`filter'的NumPy类似物 [英] NumPy analog of R's `filter`

查看:60
本文介绍了R的`filter'的NumPy类似物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

R的 在NumPy中过滤 ?

我有以下R代码:

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

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

Where x is some 1-D timeseries vector which may contain nan's.

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

How to perform the same operation using NumPy? (or any other python libs)

推荐答案

我认为 scipy过滤器功能可以满足您的要求,尤其是此操作指南:

I think the scipy filter functions do what you want, in particular lfilter. Going from this HOWTO:

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

这篇关于R的`filter'的NumPy类似物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆