[PYTHON MATRIX-SIG] arrays from text?

Konrad Hinsen hinsen@ibs.ibs.fr
Fri, 25 Oct 96 10:45:04 +0100


> Is there a way to (quickly) generate an array of numbers from an array of  
> their string representations?  More specifically, if I have an array a of Char  
> in which each row contains a printed representation of a Float, is there a  
> faster way to get an array of Floats than the following?
> 
> array(map(lambda b: string.atof(b.tostring()), a))

Nothing I know of, and even the map() solution get more complicated
for arrays of higher rank. I do have a simple module that reads
rank-1 and rank-2 arrays from files (and reads them), but in terms
of efficiency it's even worse. I have decided more than once to do
a C module, but of course I never found the time.

> Even better would be the ability to use the equivalent of FORTRAN format  
> statements and implicit loops to read in several arrays of different types  
> simultaneously from either a Char array or a file.  Anyone know how hard this  
> would be to do?

Not too hard, but still a lot of work. Especially since I want such
a module to be able to read all reasonable representations for numbers,
including Fortran double precision (with a D instead of an E) and
Mathematica format (e.g. 2.5*10^3).

> Of course, the reason for doing this is that with array operations as fast as  
> they are, the bottleneck in many programs will be the time needed to read in  
> text files, which won't be any faster.

And that is exactly my observation in practice. I/O is frustratingly
slow!

Konrad.
-- 
-------------------------------------------------------------------------------
Konrad Hinsen                          | E-Mail: hinsen@ibs.ibs.fr
Laboratoire de Dynamique Moleculaire   | Tel.: +33-76.88.99.28
Institut de Biologie Structurale       | Fax:  +33-76.88.54.94
41, av. des Martyrs                    | Deutsch/Esperanto/English/
38027 Grenoble Cedex 1, France         | Nederlands/Francais
-------------------------------------------------------------------------------

=================
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================