2016-12-16 15 views
3

scipy.interpolate.griddataを使って補間しようとするデータがあります。`scipy.interpolate.griddata`が読み込み専用配列で失敗するのはなぜですか?

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) 

は、次の例外が得られます:私のユースケースでは、私は明らかに補間壊し、読み取り専用numpyの配列の一部にマーク明らかに

--------------------------------------------------------------------------- 
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 

を、補間機能は好きではありません。アレイが書き込み保護されていること。しかし、私はなぜこれを変更したいのか理解していません。補間関数を呼び出すことによって入力が変更されるとは思っていませんが、これはドキュメントではわかりません。なぜ関数はこのように振る舞うでしょうか?

x0の代わりにx1を読み取り専用に設定すると、同様のエラーが発生することに注意してください。

答えて

2

relevant codeはCythonで書かれていて、入力配列のメモリビューが必要な場合でもit always asks for a writeable oneを要求します。

書き込み不能とフラグが立てられた配列は書き込み可能なメモリビューを提供することを拒否するため、最初に配列に書き込む必要はなくてもコードは失敗します。

+0

これはエラーを説明していますが、私はまだそれ自体がコピーを作成せずにエラーをスローするscipyのバグだと思います。最終的には、cythonはおそらく読み取り専用メモリビューを許可するように変更する必要があります。 scipy(https://github.com/scipy/scipy/issues/6864)のバグレポートを開いた。みんなが他に何を言っているのか見てみましょう –

関連する問題