【问题标题】:Scipy griddata doesn't work inside a loop / memory leakScipy griddata 在循环/内存泄漏中不起作用
【发布时间】: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


【解决方案1】:

这是一个bug in Cython,应该在 Scipy 的最终 0.12.0 版本中解决。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-08
    • 2014-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-08
    • 2016-01-13
    相关资源
    最近更新 更多