Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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插值二维误差m>;=(kx+;1)(ky+;1)必须保持_Python_Scipy - Fatal编程技术网

Python Scipy插值二维误差m>;=(kx+;1)(ky+;1)必须保持

Python Scipy插值二维误差m>;=(kx+;1)(ky+;1)必须保持,python,scipy,Python,Scipy,我想使用Scipy插值2D选项来预测“训练”点以外的点的值。我有一个value=f(b_1,b_2)函数,我想对它进行近似/插值。matplotlib能够使用给定数据进行插值并绘制。 我尝试使用scipy.interpolate.interp2d,但没有成功,因为执行时发生了错误 raise TypeError('m >= (kx+1)(ky+1) must hold') TypeError: m >= (kx+1)(ky+1) must hold 代码如下: from scip

我想使用Scipy插值2D选项来预测“训练”点以外的点的值。我有一个value=f(b_1,b_2)函数,我想对它进行近似/插值。matplotlib能够使用给定数据进行插值并绘制。

我尝试使用scipy.interpolate.interp2d,但没有成功,因为执行时发生了错误

raise TypeError('m >= (kx+1)(ky+1) must hold')
TypeError: m >= (kx+1)(ky+1) must hold
代码如下:

from scipy import interpolate
import scipy
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt 

calibration = {'b_1_probe1':    [-2,1.0,2.0,-2.0,1.5,0.0,1.0,2.0,2.0,-2.0,-0.8,-0.6],
'b_2_probe1':                  [-2,-2.0,0.4,2,1.0,0.0,2.0,2.0,-2.0,0.0,0.6,-0.7],
'value':            [5.0,6.0,3.0,4.0,-2.0,3.0,5.0,-3.0,-4.0,1.0,-2.0,3.0],
'value_A_t':            [2.0,3.0,4.0,5.0,1.0,2.0,3.0,-4.0,-2.0,2.0,-3.0,1.0]}
calibration = pd.DataFrame(calibration,columns= ['b_1_probe1','b_2_probe1','value','second_value'])
x = calibration['b_1_probe1']
y = calibration['b_2_probe1']
z = calibration['value']
f, ax = plt.subplots(1,2, sharex=True, sharey=True)
ax[0].tripcolor(x,y,z,shading='gouraud')
ax[1].tricontourf(x,y,z, 20) # choose 20 contour levels, just to show how good its interpolation is
ax[1].plot(x,y, 'ko ')
ax[0].plot(x,y, 'ko ')
plt.xlim(-2, 2)
plt.ylim(-2, 2)
plt.show()

# Interpolation goes here
f=scipy.interpolate.interp2d(x, y, z, kind='cubic', copy=True, bounds_error=False, fill_value=None)

test = {'b_1':    [-1.8,-0.5,0.4,2,1.0,0.0,1.4,0.6,-1.0,0.0,0.6,-0.7],
        'b_2':    [1.8,1.0,2.0,-1.4,1.5,0.0,1.0,2.0,2.0,-2.0,-0.8,-0.6]}
test = pd.DataFrame(test,columns= ['b_1','b_2'])
xnew = test['b_1']
ynew = test['b_2']
znew = f(xnew, ynew)
plt.plot(x, z[0, :], 'ro-', xnew, znew[0, :], 'b-')
plt.show()

我希望scipy.interpolate能够根据给定的数据进行插值,并在绘图中显示,这样我就可以比较插值前后的颜色轮廓。

类型错误不太清楚,但是如果你深入研究插值代码,你会发现
kx=ky=3
对于
cubic
插值和
m=len(x)
,所以
m>=(kx+1)(ky+1)
不是真的。如果您使用
kind='linear'
它将起作用(尽管代码中还有其他一些bug)。这在
interp2d

中注意到
类型错误
不是很清楚,但是如果你深入研究插值代码,你会发现
kx=ky=3
对于
cubic
插值和
m=len(x)
,因此
m>=(kx+1)(ky+1)
不是真的。如果您使用
kind='linear'
它将起作用(尽管代码中还有其他一些bug)。这在
interp2d

中有说明,我使用scipy.interpolate.LinearNDInterpolator解决了它。

我使用scipy.interpolate.LinearNDInterpolator解决了它