2014-02-16 42 views
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-665a00a0.13.0.dev-61f05fe

有没有人有任何想法是什么问题?

+0

因此,似乎我的scipy和numpy版本已过时。更新这些库解决了这个问题。版本现在是'1.8.0'和'0.13.3'。 –

+0

是的,最好使用发布的版本而不是(过时的)开发版本,因为前者更好地针对对方进行测试。 –

+0

当然。我确信我有。事实证明,这是一个安装了自制软件的版本与旧版本之间的冲突,这个版本与OS X附带的默认Python一起安装。 –

回答