MemoryError when list append... plz help
bearophileHUGS at lycos.com
bearophileHUGS at lycos.com
Wed Dec 31 03:52:40 EST 2008
[BON]:
> above sim is floating type.
> s.append is totally coducted 60,494,500 times.
> but this code raise MemoryError.
>
> My computer has 4G RAM.
> i think it's enough. but it doesn't...
Try creating it in a more clean way, here an array of doubles:
>>> from array import array
>>> a = array("d", [0.0]) * 60494500
This requires about 477 MB to me.
Note that I have not used "append" that slows down code a lot and
wastes memory, that's what I mean with "clean".
If you really need the (i,j) part too (and you may not need it), then
you can create two more "parallel arrays". Also a numpy array may be
better for such large amount of data.
Bye,
bearophile
More information about the Python-list
mailing list