[Numpy-discussion] Appending data to a big ndarray

Travis E. Oliphant oliphant@enthought....
Fri Aug 8 18:03:04 CDT 2008


oc-spam66 wrote:
> Hello,
>
> I would like to build a big ndarray by adding rows progressively.
>
> I considered the following functions : append, concatenate, vstack and 
> the like.
> It appears to me that they all create a new array (which requires 
> twice the memory).
>
> Is there a method for just adding a row to a ndarray without 
> duplicating the data ?
You can resize the memory for an array with the resize method.    You 
have to be careful using this approach if you have other views looking 
at the same memory because the resize method may move the pointer which 
is very bad for all the other items looking at it:

a = array([1,2,3,4])
a.resize((10,4))


-Travis




More information about the Numpy-discussion mailing list