How do I loop through a large dataset in python without getting a MemoryError?

前端 未结 2 2029
自闭症患者
自闭症患者 2021-02-08 02:47

I have a large series of raster datasets representing monthly rainfall over several decades. I\'ve written a script in Python that loops over each raster and does the following:

2条回答
  •  一生所求
    2021-02-08 03:15

    You don't need to concern youself with memory management, especially not with the garbage collector that has a very specific task that you most likely don't even use. Python will always collect the memory it can and reuse it.

    There are just two reasons for your problem: Either the data you try to load is too much to fit into memory or your calculations store data somewhere (a list, dict, something persistent between iterations) and that storage grows and grows. Memory profilers can help finding that.

提交回复
热议问题