Adding rows to arrays

Alex Martelli aleaxit at yahoo.com
Thu May 31 04:54:44 EDT 2001


"Prem Rachakonda" <prem at engr.uky.edu> wrote in message
news:e56d8da7.0105301506.42cdb335 at posting.google.com...
> Hi,
>   If I start with a 1-dimensional array (1 X 100) and I would like to
> increase the number of rows and make it 10 X 100 how would I do that.
> I have to append array in a loop.

I guess what you have and describe as "a 1-dimensional array"
is in fact a list?  Or IS it an array.array, or Numeric.array?

The latter would be the simplest case to handle:

>>> import Numeric
>>> x=Numeric.array(range(100))
>>> Numeric.shape(x)
(100,)
>>> y=Numeric.resize(x,(10,100))
>>> Numeric.shape(y)
(10, 100)

array.array can't be 2-dimensional.  a list can, in a sense: it
can be a list of lists.  For example:

>>> x=range(100)
>>> y=[x[:] for i in range(10)]

this is roughly the equivalent of the Numeric code above.


Alex






More information about the Python-list mailing list