[Numpy-discussion] appending extra items to arrays

Timothy Hochberg tim.hochberg@ieee....
Thu Oct 11 09:02:04 CDT 2007


On 10/10/07, Anne Archibald <peridot.faceted@gmail.com> wrote:
>
> On 11/10/2007, Robert Kern <robert.kern@gmail.com> wrote:
>
> > Appending to a list then converting the list to an array is the most
> > straightforward way to do it. If the performance of this isn't a
> problem, I
> > recommend leaving it alone.
>
> Just a speculation:
>
> Python strings have a similar problem - they're immutable, and so are
> even more resistant to growth than numpy arrays. For those situations
> where you really really want to grow a srting, python provides
> StringIO, where you keep efficiently adding to the string, then
> finalize it to get the real string out. Would something analogous be
> interesting for arrays?


Have you looked at array.array?

>>> import array
>>> a = array.array('i')
>>> a.append(2)
>>> a.append(7)
>>> a
array('i', [2, 7])




-- 
.  __
.   |-\
.
.  tim.hochberg@ieee.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20071011/34b2f572/attachment.html 


More information about the Numpy-discussion mailing list