0
我試圖在Scipy中使用griddata方法對一組數據執行雙三次插值。但是每次嘗試時,我都會得到ValueError'Buffer not C contiguous'。Scipy的griddata方法總是失敗
奇怪的是,我跑,他們給的例子算法,它仍然失敗:
def func(x, y):
return x*(1-x)*np.cos(4*np.pi*x) * np.sin(4*np.pi*y**2)**2
def bicubic():
grid_x, grid_y = np.mgrid[0:1:100j, 0:1:200j]
points = np.random.rand(1000, 2)
values = func(points[:,0], points[:,1])
data = griddata(points, values, (grid_x, grid_y), method='cubic')
return data
堆棧跟蹤爲:
Traceback (most recent call last):
File "parser.py", line 135, in <module>
ZI = bicubic(xv,yv,values,gridx,gridy)
File "/Users/Velox/Dropbox/Uni/Masters Project/Data/OpenSense/bicubic.py", line 14, in bicubic
return griddata(points, values, (grid_x, grid_y), method='cubic')
File "/Library/Python/2.7/site-packages/scipy/interpolate/ndgriddata.py", line 187, in griddata
ip = CloughTocher2DInterpolator(points, values, fill_value=fill_value)
File "interpnd.pyx", line 803, in scipy.interpolate.interpnd.CloughTocher2DInterpolator.__init__ (scipy/interpolate/interpnd.c:8584)
File "interpnd.pyx", line 478, in scipy.interpolate.interpnd.estimate_gradients_2d_global (scipy/interpolate/interpnd.c:6644)
ValueError: Buffer not C contiguous.
與NumPy和SciPy的的版本分別爲1.8.0.dev-665a00a
和0.13.0.dev-61f05fe
。
有沒有人有任何想法是什麼問題?
因此,似乎我的scipy和numpy版本已過時。更新這些庫解決了這個問題。版本現在是'1.8.0'和'0.13.3'。 –
是的,最好使用發佈的版本而不是(過時的)開發版本,因爲前者更好地針對對方進行測試。 –
當然。我確信我有。事實證明,這是一個安裝了自制軟件的版本與舊版本之間的衝突,這個版本與OS X附帶的默認Python一起安裝。 –