[SciPy-dev] Reading in arrays.

Travis Oliphant oliphant at ee.byu.edu
Thu Oct 25 11:03:25 CDT 2001

As eric pointed out reading arrays of ASCII data is actually quite easy
(and fairly sophisticated).   It is available thanks to the support of
Agilent who has given some money for the development of SciPy.

Reading ascii data can be as simple as

a = io.read_array('test.dat')   # you can pass a string object already.

to read in space-separated data as an array of doubles.

Eric,  Why on earth would you reach for Excel now that you have it this
easy?  (Except for maybe getting better graphics on windows --- if you
have an X-server you can already do quite a bit).

I'm not sure I agree with Eric that this is "buried" way to deep.

io.read_array does not seem very deep to me.

There are many options which can make the reading in easier.

>>> help(io.read_array)
 read_array(fileobject, separator=None, columns=None, comment='#', lines=None,
            atype='d', linesep='\n', rowsize=10000, missing=0)

Return an array represented ascii_formatted data in |fileobject|.


  fileobject -- An open file object or a string for a valid filename.
  separator -- a string or a tuple of strings to indicate the column
               separators.  If the length of the string tuple is less
               than the total number of columns, then the last separator
               is assumed to be the separator for the rest of the columns.
  columns -- a tuple of integers and range-tuples which describe the
             columns to read from the file.  A negative entry in the
             last column specifies the negative skip value to the end.
             Example:  columns=(1, 4, (5, 9), (11, 15, 3), 17, -2)
                     will read [1,4,5,6,7,8,11,14,17,18,20,22,...]
  lines   -- a tuple with the same structure as columns which indicates
             the lines to read.
  comment -- the comment character (line will be ignored even if it is
             specified by the lines tuple)
  linesep -- separator between rows.
  missing -- value to insert in array when conversion to number fails.
  atype -- the typecode of the output array.
  rowsize -- the allocation row size (array grows by this amount as
           data is read in).

Adding wizards to make this more "interactive" may be useful especially
for beginners.

But, the functionality is there.


More information about the Scipy-dev mailing list