【问题标题】:Pandas.rolling().median vs Scipy.signal.medfilt()Pandas.rolling().median 与 Scipy.signal.medfilt()
【发布时间】:2020-08-02 21:31:35
【问题描述】:

我申请了Pandas.rolling().median(),它有一个延迟相移(绿线)。

如果我使用Scipy.signal.medfilt(),结果不会移动(黄线)。

为什么,结果不一样?

附:我试图研究使用 sigtools._order_filterND 的 medfilt 实现,我认为它不在 python 中。

代码:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import medfilt

x = np.zeros(100)
x[30:70] = 2
x+= .1 * np.random.randn(100)

y1 = medfilt(x, kernel_size=5)

plt.plot(x, '.-', label='original signal');
plt.plot(y1, '.-', alpha=.5, label='medfilt'); 
plt.plot(pd.Series(x).rolling(5).median(), label='rolling window');
plt.legend();

【问题讨论】:

    标签: pandas scipy filtering signal-processing smoothing


    【解决方案1】:

    您是否尝试在滚动时使窗口居中?

    Pandas.rolling(center=True).median()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-22
      • 2018-12-29
      • 2022-11-18
      • 2013-04-24
      • 2016-12-23
      • 2021-08-17
      • 1970-01-01
      • 2022-11-20
      相关资源
      最近更新 更多