大矩阵的SciPy插值 [英] SciPy interpolation of large matrix

查看:303
本文介绍了大矩阵的SciPy插值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ndarray(Z),在矩形网格(X,Y)上有大约500000个元素.

I have a ndarray (Z) with some 500000 elements on a rectangular grid (X, Y).

现在,我想在x,y中的大约100个位置插值,这些位置不一定在网格上.

Now I want to interpolate values at some 100 locations in x,y which are not necessarily on the grid.

我有一些在Matlab中工作的代码:

I have some code working in Matlab:

data = interp2(X,Y,Z, x,y);

但是,当我尝试对scipy.interpolate使用相同的方法时,根据方法的不同会出现各种错误.例如,如果我指定kind = 'linear',则interp2d失败,并出现MemoryError错误;如果我指定kind='cubic',则显示"OverflowError:太多数据点无法插值".我也尝试了Rbfbisplev,但是它们也失败了.

However, when I try to use the same approach with scipy.interpolate I get various errors depending on the method. For example interp2d fails with MemoryError if i specify kind = 'linear' and "OverflowError: Too many data points to interpolate" if I specify kind='cubic'. I also tried Rbf and bisplev but they also fail.

所以问题是:是否存在允许对大型矩阵进行插值的插值函数?有其他解决方法吗? (或者我是否必须编写一个函数来选择要插入点周围的适当区域,然后调用interp2d?)

So the question is: Is there an interpolation function which allows for interpolations of large matrices? Is there another solution to the problem? (Or do I have to code a function which picks the suitable area around the points to interpolate and calls then interp2d?)

此外:如何对复数进行运算?

In addition: How to do this with complex numbers?

推荐答案

由于您的数据位于网格中,因此可以使用

As your data is on a grid, you can use RectBivariateSpline.

要使用复数,可以分别插值data.realdata.imag(FITPACK例程IIRC不能处理复数数据).

To work with complex numbers, you can interpolate data.real and data.imag separately (the FITPACK routines IIRC don't handle complex data).

这篇关于大矩阵的SciPy插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆