[Numpy-discussion] RAM problem during code execution - Numpya arrays

Daπid davidmenhur at gmail.com
Fri Aug 23 12:15:33 EDT 2013


On 23 August 2013 16:59, Benjamin Root <ben.root at ou.edu> wrote:
> A lot of the code you have here can be greatly simplified. I would start
> with just trying to get rid of appends as much as possible and use
> preallocated arrays with np.empty() or np.ones() or the likes.

Also, if you don't know beforehand the final size of the array (I find
difficult to follow the flow of the program, it is quite lengthy), you
can use lists as a temporary thing:

results = []
while SomeCondition:
   do_something()
   results.append(res)
results = np.array(res)

Also, it may also help to trace things down encapsulate pieces of code
inside functions. There are two reasons for this: it will make the
code more readable, easier to test, and you could run independently
pieces of code to find where is your memory growing.


I hope it is of any help.

David.



More information about the NumPy-Discussion mailing list