尝试使用scipy.signal.cwt时,我遇到了一个奇怪的错误:
我有一些列表c
,我想像这样进行连续小波变换:
scipy.signal.cwt(np.array(c), scipy.signal.morlet, np.arange(.01,.1,.01))
我得到一个奇怪的错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-55-5af5e14b96cd> in <module>()
----> 1 sig.cwt(a, sig.morlet, np.arange(.01,.1,.01))
/usr/local/lib/python2.7/site-packages/scipy/signal/wavelets.pyc in cwt(data, wavelet, widths)
359 wavelet_data = wavelet(min(10 * width, len(data)), width)
360 output[ind, :] = convolve(data, wavelet_data,
--> 361 mode='same')
362 return output
/usr/local/lib/python2.7/site-packages/scipy/signal/signaltools.pyc in convolve(in1, in2, mode)
270
271 if np.iscomplexobj(kernel):
--> 272 return correlate(volume, kernel[slice_obj].conj(), mode)
273 else:
274 return correlate(volume, kernel[slice_obj], mode)
/usr/local/lib/python2.7/site-packages/scipy/signal/signaltools.pyc in correlate(in1, in2, mode)
129 in1zpadded = np.zeros(ps, in1.dtype)
130 sc = [slice(0, i) for i in in1.shape]
--> 131 in1zpadded[sc] = in1.copy()
132
133 if mode == 'full':
ValueError: could not broadcast input array from shape (66467) into shape (66466)
导致此错误的原因是什么?
答案 0 :(得分:4)
scipy.signal.cwt
的第三个参数是宽度,必须大于1,因此请将代码更改为:
scipy.signal.cwt(np.array(c), scipy.signal.morlet, np.arange(.01,.1,.01) * len(c))