How to add columns to python arrays

Terry Reedy tjreedy at udel.edu
Wed May 17 14:54:57 EDT 2006


"CC" <chuangwoo at gmail.com> wrote in message 
news:1147882432.166728.207820 at j55g2000cwa.googlegroups.com...
> I wanna compile a 6000x1000 array with python. The array starts from
> 'empty', each time I get a 6000 length list, I wanna add it to the
> exist array as a column vector. Is there any function to do so?
>
> Or, I can add the list as a rows, if this is easier, and transpose the
> whole array after all the rows are setup.

Python does not come with a 2D array type either as a builtin type or as a 
standard library module.  You can only simulate one with a sequence of 
sequences (list of lists, for instance).  You could initialize as follows:

aray = []
for l6000 in source(): aray.append(l6000)

While this will print as a list of rows, you are free to think of it as a 
list of columns.

That said, I suspect you should use the 3rd party NumPy package which 
defines multiple-dimensional arrays of several base types.

Terry Jan Reedy






More information about the Python-list mailing list