Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么'scipy.interpolate.griddata'对于只读数组失败?_Python_Numpy_Scipy - Fatal编程技术网

Python 为什么'scipy.interpolate.griddata'对于只读数组失败?

Python 为什么'scipy.interpolate.griddata'对于只读数组失败?,python,numpy,scipy,Python,Numpy,Scipy,我有一些数据,我尝试使用scipy.interpolate.griddata进行插值。在我的用例中,我将一些numpy数组标记为只读,这显然破坏了插值: import numpy as np from scipy import interpolate x0 = 10 * np.random.randn(100, 2) y0 = np.random.randn(100) x1 = np.random.randn(3, 2) x0.flags.writeable = False # x1.fla

我有一些数据,我尝试使用
scipy.interpolate.griddata
进行插值。在我的用例中,我将一些numpy数组标记为只读,这显然破坏了插值:

import numpy as np
from scipy import interpolate

x0 = 10 * np.random.randn(100, 2)
y0 = np.random.randn(100)
x1 = np.random.randn(3, 2)

x0.flags.writeable = False
# x1.flags.writeable = False

interpolate.griddata(x0, y0, x1)
产生以下异常:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-14-a6e09dbdd371> in <module>()
      6 # x1.flags.writeable = False
      7 
----> 8 interpolate.griddata(x0, y0, x1)

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/scipy/interpolate/ndgriddata.pyc in griddata(points, values, xi, method, fill_value, rescale)
    216         ip = LinearNDInterpolator(points, values, fill_value=fill_value,
    217                                   rescale=rescale)
--> 218         return ip(xi)
    219     elif method == 'cubic' and ndim == 2:
    220         ip = CloughTocher2DInterpolator(points, values, fill_value=fill_value,

scipy/interpolate/interpnd.pyx in scipy.interpolate.interpnd.NDInterpolatorBase.__call__ (scipy/interpolate/interpnd.c:3930)()

scipy/interpolate/interpnd.pyx in scipy.interpolate.interpnd.LinearNDInterpolator._evaluate_double (scipy/interpolate/interpnd.c:5267)()

scipy/interpolate/interpnd.pyx in scipy.interpolate.interpnd.LinearNDInterpolator._do_evaluate (scipy/interpolate/interpnd.c:6006)()

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/scipy/interpolate/interpnd.so in View.MemoryView.memoryview_cwrapper (scipy/interpolate/interpnd.c:17829)()

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/scipy/interpolate/interpnd.so in View.MemoryView.memoryview.__cinit__ (scipy/interpolate/interpnd.c:14104)()

ValueError: buffer source array is read-only
---------------------------------------------------------------------------
ValueError回溯(最近一次调用上次)
在()
6#x1.flags.writeable=False
7.
---->8插值网格数据(x0,y0,x1)
/GoDe/Opt/Loopy/Fruts/Python .FrasWorks/VoRoSs/2.7/LIb/PythON2.7/SIT-PACGESS/SCIPY/IPLATEAT/NDGRIDATATE.PYC(GRIDDATA(点,值,席,方法,FILIL值,RESCALE))
216 ip=LinearNDInterpolator(点、值、填充值=填充值、,
217重缩放=重缩放)
-->218返回ip(xi)
219 elif方法=='cubic'和ndim==2:
220 ip=Cloughtocher2插值器(点、值、填充值=填充值、,
scipy.interpolatorbase.中的scipy/interpolate/interpnd.pyx。调用(scipy/interpolate/interpnd.c:3930)()
scipy/INTERPOLE/INTERPOND.pyx中的scipy.INTERPOLE.INTERPOND.LINEARDINTERPOLATOR.\u evaluate\u double(scipy/INTERPOLE/INTERPOND.c:5267)()
scipy/INTERPOLE/INTERPOND.pyx在scipy.INTERPOLE.INTERPOND.LINEARDINTERPOLATOR.中的scipy/INTERPOLE/INTERPOND.pyx进行求值(scipy/INTERPOLE/INTERPOND.c:6006)()
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/scipy/interpolate/interpnd.so in View.MemoryView.MemoryView_cwrapper(scipy/interpolate/interpnd.c:17829)()
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/scipy/interpolate/interpnd.so in View.MemoryView.MemoryView.\uu cinit\uuuuu(scipy/interpolate/interpnd.c:14104)()
ValueError:缓冲区源数组为只读
显然,插值函数不喜欢数组是写保护的。但是,我不明白他们为什么要改变这一点——我当然不希望调用插值函数会改变我的输入,就我所知,文档中也没有提到这一点。为什么函数的行为会像他的

请注意,将
x1
设置为只读而不是
x0
会导致类似的错误。

使用Cython编写,并且当Cython请求输入数组的内存视图时,即使您不需要它


由于标记为不可写的数组将拒绝提供可写的memoryview,因此代码失败,即使它不需要首先写入数组。

我明白了–这解释了错误,但我仍然认为scipy中的一个错误是不复制本身而是抛出错误。最终,cython可能应该改为al低只读内存视图。我打开了scipy()的错误报告。让我们看看其他人怎么说