[Numpy-discussion] matrix file format

Christopher Lee clee at gnwy100.wuh.wustl.edu
Tue Dec 12 12:03:26 EST 2000


You have many options:  

I frequently use Konrad Hinsen's "Scientific" package
(http://dirac.cnrs-orleans.fr/programs/scientific.html).  It make importing
files from user input or other packages like matlab easy and supports
several file formats.  The simpliest is a basic white-space-delimitted text file

if you have a text file "arrayfile.txt" that looks like this:

# arrayfile.txt (lines beginning  with '#' are ignored)
1 2 3
4 5 6
6 8 9

You can fire up python and read in your matrix like this:

   >>> from Scientific.IO.ArrayIO import readArray
   >>> A = readArray('arrayfile.txt')
   >>> print A
   [[1 2 3]
    [4 5 6]
    [6 8 9]]



More information about the NumPy-Discussion mailing list