Scipy 的 griddata 方法总是失败 [英] Scipy's griddata method always fails

查看:72
本文介绍了Scipy 的 griddata 方法总是失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to use the griddata method in Scipy to perform bicubic interpolation on a set of data. However every time I try I get the ValueError 'Buffer not C contiguous'.

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

The weird thing is that I'm running the example algorithm that they give and it still fails:

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.

The versions of Numpy and Scipy are 1.8.0.dev-665a00a and 0.13.0.dev-61f05fe respectively.

有人知道出了什么问题吗?

Does anyone have any ideas what is going wrong?

推荐答案

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

So this was an issue with an out of date version of numpy. The bug can be seen here: https://github.com/numpy/numpy/issues/2956

这篇关于Scipy 的 griddata 方法总是失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆