|
From: Daπid <dav...@gm...> - 2012-09-11 13:00:48
|
On Sunday, September 9, 2012, Eric Firing wrote: > Regarding the need to pre-allocate: yes, matlab is slicker in this > regard, and every now and then there is discussion about implementing > equivalent behavior in numpy, or in an add-on module. > Technically, you don´t have to preallocate the memory, but every time you expand your array, the whole of it will be copied to a new contiguous piece of memory. This works, but it can be slow if you do it many times, or you are handling big data. Using a Python list is not much more flexible, but you could use carrays (for chunked arrays), that are structures NumPyArrays-compatible (AFAIK) that are stored non contiguosly in memory. Adding data only needs to move one of those small pieces, instead of the whole array. |