Package Scientific :: Package IO :: Module ArrayIO
[frames] | no frames]

Module ArrayIO

Basic support for I/O of one- and two-dimensional numerical arrays to and from plain text files

The text file format is very simple and used by many other programs as well:

An array containing only one line or one column is returned as a one-dimensional array on reading. One-dimensional arrays are written as one item per line.

Numbers in files to be read must conform to Python/C syntax. For reading files containing Fortran-style double-precision numbers (exponent prefixed by D), use the module Scientific.IO.FortranFormat.

Functions
Numeric.array
readArray(filename)
Read array data from a file
Numeric.array of float
readFloatArray(filename)
Read array data from a file into an array of floats
Numeric.array of int
readIntegerArray(filename)
Read array data from a file into an array of integers
 
writeArray(array, filename, mode='w')
Write a text representation of an array to a file.
 
writeDataSets(datasets, filename, separator='')
Write multiple datasets to a text file.
Function Details

readArray(filename)

 

Read array data from a file

This function works for arbitrary data types (every array element can be given by an arbitrary Python expression), but at the price of being slow. For large arrays, use readFloatArray or readIntegerArray if possible.

Parameters:
  • filename (str) - the name of the file to read
Returns: Numeric.array
an array containing the data from the file

readFloatArray(filename)

 

Read array data from a file into an array of floats

Parameters:
  • filename (str) - the name of the file to read
Returns: Numeric.array of float
an array containing the data from the file

readIntegerArray(filename)

 

Read array data from a file into an array of integers

Parameters:
  • filename (str) - the name of the file to read
Returns: Numeric.array of int
an array containing the data from the file

writeArray(array, filename, mode='w')

 

Write a text representation of an array to a file.

Parameters:
  • array (Numeric.array) - the array to be written
  • filename (str) - the name of the output file
  • mode (str) - the file access mode, 'w' (new file) or 'a' (append)

writeDataSets(datasets, filename, separator='')

 

Write multiple datasets to a text file.

Parameters:
  • datasets - a sequence of datasets describing a curve to be plotted. Each dataset is either a 1d-array (list of values) or a 2d-array of shape N x 2 (list of (x, y) pairs). Nested lists can be used instead of arrays.
  • filename (str) - the name of the output file
  • separator (str) - the contents of the line that is written between two datasets