我有一个[t, y(t)]
形式的大型数据集,我想使用scipy.signal
(特别是scipy.filter.butter
和scipy.filter.filtfilt
)对其应用IIR低通滤波器(一阶或二阶巴特沃斯就足够了)。问题是t
不是规则间隔的,这似乎是scipy.signal
中函数的一个要求。你知道吗
对于任何“缺失”的点,我知道我的信号与其之前的值保持不变(因此给定我的t
-数据中的两个连续点t1
和t2
,以及数据中的一个点T
,这样t1<T<t2
,我正在采样的“实”函数Y(t)
将取值Y(T)=Y(t1)
)。t
是整数值,因此我可以简单地添加缺失的点,但这会导致数据集的大小增加约10倍,这是有问题的,因为它已经非常大了。你知道吗
所以问题是,有没有一种(足够简单和低开销)的方法来过滤我的数据集而不插入所有的“缺失”点?你知道吗
您可以有效地将数据“包装”到函数中。你知道吗
如果您的数据是列表形式的,那么您需要将其转换为} 模块中的列表对分算法对缺少的值进行插值。你知道吗
dict
,并创建t
值的排序列表。然后,您可以使用^{这里有一些用python2编写的演示代码,但是如果需要的话,可以直接将其转换为python3。你知道吗
输出
(我手动包装了
keys
的输出,以便在没有水平滚动的情况下更易于阅读)。你知道吗通过在一行中重新写入插值函数体,您将获得一个微小的加速:
它的可读性要差得多,IMHO,但是如果函数被频繁调用,那么速度差可能是值得的。你知道吗
pm2ring给出的答案是可行的,但是假设您的数据已经由
t
排序,那么它的效率就比可能的低。它需要对数线性时间和线性附加空间。您可以编写一个生成器,以在线性时间和恒定的附加空间中生成具有规则采样间隔的转换数据集:测试:
输出:
相关问题 更多 >
编程相关推荐