SciPy interp2d内存错误,正在寻找替代方法 [英] SciPy interp2d Memory Error, looking for alternative

查看:99
本文介绍了SciPy interp2d内存错误,正在寻找替代方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NumPy和SciPy将MATLAB程序转换为Python程序,但我仍然是新手.在程序的一部分中,我具有以下MATLAB代码:

I am converting an MATLAB program to a Python program using NumPy and SciPy and I am still new to it. In part of the program, I have the following MATLAB code:

tImg(:,:,1) = interp2(x,y,Img(:,:,1),Tx,Ty,'cubic');

interp2方法中的所有参数均为298x142 double.

All parameters in the interp2 method are 298x142 double.

所以我试图将其转换为以下Python代码:

So I tried to convert it to the following Python code:

tImg[:, :, 0] = (scipy.interpolate.interp2d(x, y, img[:, :, 0], kind='cubic'))(Tx, Ty)

我在interp2d方法中收到MemoryError. MATLAB代码运行良好.我已经阅读了插值文档,但似乎找不到解决方法.

I am given MemoryError in the interp2d method. The MATLAB code runs fine. I have read through the interpolation documentation but I don't seem to find a solution.

我使用scipy 0.16.0使用3GB内存运行以上代码.

I run the code above with 3GB memory, with scipy 0.16.0.

感谢您的帮助.谢谢.

Any help is appreciated. Thanks.

推荐答案

我怀疑问题是TxTy对于MATLAB的interp2函数和scipy.interpolate.interp2d的含义不同.

I suspect the problem is that Tx and Ty mean different things for MATLAB's interp2 function and scipy.interpolate.interp2d.

在MATLAB interp2函数中,TxTy将是2D数组,它们为每个单独的输出点指定x,y坐标,因此结果将是一个具有与TxTy相同的形状,即:

In the MATLAB interp2 function, Tx and Ty would be 2D arrays that specify the x,y coordinates for each individual output point, so the result would be a vector with the same shape as Tx and Ty, i.e.:

timg(i, j, 1) = interp2(x, y, Img(i, j, 1), Tx(i, j),Ty(i, j), 'cubic');

scipy.interpolate.interp2d中,TxTy应该是一维矢量,用于指定要评估插值的常规网格的行和列的x和y坐标,即:

In scipy.interpolate.interp2d, Tx and Ty should be 1D vectors that specify the x and y coordinates for the rows and columns for a regular mesh over which the interpolant is to be evaluated, i.e.:

timg[i, j, 0] = intp(Tx[i], Ty[j])

我怀疑您正在传递要插入的每个点的坐标,在这种情况下,您将得到一个(nx*ny, nx*ny)输出.如果nx = 298ny = 142,则将生成一个(42316, 42316)数组.假设它包含64位浮点数,则总共将占用约14GB的内存.

I suspect that you are passing the coordinates of every point you want to interpolate at, in which case you will get an (nx*ny, nx*ny) output. If nx = 298 and ny = 142 then you would generate an (42316, 42316) array. Assuming it contains 64 bit floats, that would take up about 14GB of memory in total.

这篇关于SciPy interp2d内存错误,正在寻找替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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