[Numpy-discussion] appending extra items to arrays
Robert Kern
robert.kern at gmail.com
Thu Oct 11 01:10:49 EDT 2007
Anne Archibald wrote:
> On 11/10/2007, Robert Kern <robert.kern at 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?
The Python version of StringIO, at least, just keeps a list, too. The primary
benefit of StringIO is that it exposes the file interface. For building up a
string/array, using the list is just as convenient (and for arrays, probably
more convenient given the variety of shapes one might want to build) and at
least as readable.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the NumPy-Discussion
mailing list