【问题标题】:Trapezoidal Kernel in pythonpython中的梯形内核
【发布时间】:2017-06-15 19:57:07
【问题描述】:

我想在 python 中实现一个梯形内核(可能使用 numpy 或 scipy)进行卷积,就像在 astropy 模块中作为 Trapezoidal1Dkernel 一样。我曾尝试用梯形波形进行卷积,但结果并不理想。

def trapzoid_signal(t, width=2., slope=1., amp=1., offs=0):
    global trasig
    trasig=[]
    trasig = slope*width*signal.sawtooth(2*np.pi*t/width, width=0.5)/4.
    trasig+= slope*width/4.
    trasig[trasig>amp] = amp
    return trasig + offs
t = np.linspace(0, 32, 34)
trapzoid_signal(t, width=32, slope=1, amp=0.0322)
print(trasig)
z = scipy.signal.convolve(trasig,new)

如果我打印 z 它给出:

[ nan  nan  nan ...,  nan  nan  nan]

我尝试绘制 z 它没有给出任何结果。有什么帮助吗?

【问题讨论】:

标签: python-3.x numpy scipy convolution


【解决方案1】:

尤里卡!!!我做的。使用我在 StackOverflow 本身上找到的以下代码删除了为什么它没有将值绘制或打印为 [ nan nan nan ..., nan nan nan] 的问题。

ind = np.where(~np.isnan(new))[0]
first, last = ind[0], ind[-1]
new[:first] = new[first]
new[last + 1:] = new[last]

然后它解决了我的问题。我不仅得到了 z 的值,还得到了我的情节。感谢 stackoverflow.com。

【讨论】:

    猜你喜欢
    • 2017-11-16
    • 2014-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-17
    • 2015-07-06
    • 2016-04-25
    相关资源
    最近更新 更多