[Numpy-discussion] best way for storing extensible data?

Anne Archibald peridot.faceted at gmail.com
Fri May 18 11:01:37 EDT 2007


On 18/05/07, David M. Cooke <cookedm at physics.mcmaster.ca> wrote:

> It'll act like appending to a list, where it will grow the array (by
> doubling, I think) when it needs to, so appending each value is
> amortized to O(1) time. A list though would use more memory
> per element as each element is a full Python object.

That said, don't be afraid to use a list. The memory penalty is not
high (an extra 50% or 100% or so, just what it costs to duplicate an
array, and about as much as is wasted in the amortizing) and python's
list-handling can be quite efficient and convenient. List
comprehensions, in particular, can be a very good way to write array
operations that would otherwise be cumbersome. Iterator comprehensions
can fill some of the same role.

Anne



More information about the NumPy-Discussion mailing list