【发布时间】:2013-03-18 01:21:35
【问题描述】:
我在循环中使用 Scipy 的 griddata 时遇到问题。基本上发生的情况是内存在循环运行时无限制地增长。
要重现问题,只需将示例放入
http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.griddata.html
在循环内:
for i in range(100000):
grid_z1 = griddata(points, values, (grid_x, grid_y), method='linear')
我的 Python 版本是 2.7.3,我的 numpy 版本是 1.7.0,我的 scipy 版本是 0.12.0b1。我在 Windows 7 上运行它。
这是一个错误吗?如何多次重复插值而不发生内存泄漏问题?
剩下的代码:
def func(x, y):
return x*(1-x)*np.cos(4*np.pi*x) * np.sin(4*np.pi*y**2)**2
grid_x, grid_y = np.mgrid[0:1:100j, 0:1:200j]
points = np.random.rand(1000, 2)
values = func(points[:,0], points[:,1])
for i in range(100000):
grid_z1 = griddata(points, values, (grid_x, grid_y), method='linear')
提前致谢。
【问题讨论】:
-
请向我们展示您的整个循环。
-
如原题所示。
-
您能否将其编辑到您的问题中?真的很难读。
-
数据点:我在 Python 2.6.6、numpy 1.6.1、scipy 0.10.1、Windows 7 上运行了您的示例,并且没有内存泄漏。
-
嗯,也许这是最新版本的 numpy/scipy 的错误。感谢您的意见。
标签: python scipy interpolation