我正在尝试使用interp2d
中的Scipy
以及以下数据:
x的形状=(1,8645) 形状y =(1,4335)
数据形状=(4335,8654)
这是我尝试过的:
ix=interpolate.interpd2d(x,y,data)
ip=ix(10.25,56.77)
我收到了这样的错误:
nx,tx,ny,ty,c,fp,ier = dfitpack.regrid_smth x,y,z,无,无, 无,无,kx = kx,ky = ky,s = 0.0)self.tck =(tx [:nx],ty [:ny],c [:( nx - kx - 1)*(ny - ky - 1)],kx,ky)
的MemoryError:
如何解决此问题?
我找到了一个将数组切成小块的选项,但它也没有用。这仅适用于方阵。
def my_interp(X, Y, Z, x, y, spn=3):
xs,ys = map(np.array,(x,y))
print xs.shape
z = np.zeros(xs.shape)
for i,(x,y) in enumerate(zip(xs,ys)):
# get the indices of the nearest x,y
xi = np.argmin(np.abs(X[0,:]-x))
yi = np.argmin(np.abs(Y[:,0]-y))
xlo = max(xi-spn, 0)
ylo = max(yi-spn, 0)
xhi = min(xi+spn, X[0,:].size)
yhi = min(yi+spn, Y[:,0].size)
# make slices of X,Y,Z that are only a few items wide
nX = X[xlo:xhi, ylo:yhi]
nY = Y[xlo:xhi, ylo:yhi]
nZ = Z[xlo:xhi, ylo:yhi]
intp = interpolate.interp2d(nX, nY, nZ)
z[i] = intp(x,y)[0]
return z