1
from scipy import ndimage
import numpy as np
with open("Data.dat", "r+") as f:
content = f.readlines()
content = [s.strip() for s in content]
content = np.asarray(content)
weights = np.array([1, 2, 4, 2, 1])
final = np.empty(content)
ndimage.filters.convolve1d(content, weights, -1, final, 'reflect', 0.0, 0.0)
這裏np
是numpy
包。 content
的長度是750,所以試圖用np.empty()初始化輸出數組的形狀,因爲我不想在那裏有任何值。ValueError異常,而使用計算卷積SciPy的
但是當我跑我得到這個錯誤:
Traceback (most recent call last):
File "C:\Users\Animesh\Desktop\Smoothing.py", line 18, in <module>
final = np.empty(content)
ValueError: sequence too large; must be smaller than 32
應該怎樣做?
替換上面我想,但我得到這個錯誤'類型錯誤:預期的整數參數,得到了float' –
我正在編輯的問題,以準確顯示我在做什麼! –
將最後一個參數從「0.0」更改爲「0」。原點參數必須是整數。 – unutbu