使用interp2d在python中插入2D数组

时间:2018-03-30 04:42:11

标签: python numpy scipy

我正在尝试使用scipy.interpolate.interp2d在python中插入2D数组中的数据。但是,我不认为我完全理解它在做什么,所以任何帮助都表示赞赏。我正在尝试做类似于Link建议的内容。

我的代码如下:

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from scipy import interpolate
from scipy.interpolate import griddata

p = np.array([[1,2,3,4,5,6,7,8,9,1],[1,2,3,4,5,6,7,8,9,1],  
              [1,6,3,4,8,6,7,8,9,1],[1,2,3,4,5,6,7,89,9,1],
              [1,56,3,4,5,6,7,67,6,1],[1,2,3,4,7,6,7,8,9,1],
              [1,2,3,5,5,6,7,6,9,1],[1,2,3,6,5,6,7,45,9,1],
              [9,2,3,4,21,6,7,8,9,1],[1,8,3,3,5,6,7,5,9,1]])
print(pf)
mymin, mymax = 0, 9
X = np.linspace(mymin,mymax,10)
Y = np.linspace(mymin,mymax,10)

Xnew = np.linspace(mymin,mymax,20)
Ynew = np.linspace(mymin,mymax,20)

f = interpolate.interp2d(x,y,p,kind='cubic')

Po = f(Xnew,Ynew)
print(Po)

运行时,会显示以下错误消息:

  

ValueError:非矩形网格的输入z的长度无效

0 个答案:

没有答案