Terry said:
CC said:
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
If you're just looking for a multi-dimensional array type, and don't need
maximum speed or the vast range of array-processing that numpy offers, then
*pyarray* provides a pure-python single module solution.
the latest pyarray is available with tests and documentation at:
http://svn.brownspencer.com/pyarray/trunk/
Introduction
============
pyarray is a pure-Python implementation of a multi-dimensional array type.
pyarray.ListView and pyarray.ArrayView offer a substantial subset of
numpy.ArrayType functionality, by wrapping standard python 'list' and
'array.array' respectively.
Key features include:
* Views: all subscripting operations apart from individual cell access
access return views to existing 'live' data
* Extended Indexing: slicing, arbitrary 'takes', index arrays etc...
* Unlimited re-shaping: while still addressing one data-source
* Elementwise binary operations: all basic arithmetic and comparison
operations
* Data broadcasting: allows assignment and binary operations between
views of different shapes
* Friendly __repr__: work safely with big arrays at the interactive prompt
Regards
Michael