[Numpy-discussion] appending extra items to arrays

David Cournapeau david at ar.media.kyoto-u.ac.jp
Thu Oct 11 00:35:14 EDT 2007


Adam Mercer wrote:
> Hi
>
> In some code I have, I need to append some extra data to a given
> array.  At the moment I construct the data in a list, append the extra
> information I need and then convert the final list to an array.  Is
> there a way that I can append extra information to an existing array
> thereby negating the need for the list, as the array object doesn't
> seem to have an append() method?
>   
Fundamentally, numpy works because its underlying data is in a block of 
memory. This is incompatible with appending data at will, which is the 
exact thing lists are good at.

Now, depending on the problem you are trying to solve, it may be better 
(read faster, more memory efficient, etc...) to use numpy arrays, and 
create new bigger ones when you need to append data. It all depends on 
your problem.

cheers,

David



More information about the NumPy-Discussion mailing list