Scipy的griddata方法总是失败

时间:2014-02-16 13:19:51

标签: python numpy scipy

我正在尝试使用Scipy中的griddata方法对一组数据执行双三次插值。但是每次我尝试时都会得到ValueError'Buffer not C contiguous'。

奇怪的是,我正在运行他们提供的示例算法,但仍然失败:

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

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

1 个答案:

答案 0 :(得分:0)

所以这是numpy的过时版本的问题。可以在这里看到错误:https://github.com/numpy/numpy/issues/2956