[Numpy-discussion] matrix file format
Konrad Hinsen
hinsen at cnrs-orleans.fr
Tue Dec 12 13:20:24 EST 2000
> I'm trying to find out what format a matrix input file should have in
> numpy.
Any format you like, but you have to supply the I/O code yourself.
Which however is really simple. For example, the following
function from ScientificPython:
from Scientific.IO.TextFile import TextFile
import string, Numeric
def readArray(filename):
"Return an array containing the data from file |filename|."
data = []
for line in TextFile(filename):
if line[0] != '#':
data.append(map(eval, string.split(line)))
a = Numeric.array(data)
if a.shape[0] == 1 or a.shape[1] == 1:
a = Numeric.ravel(a)
return a
Konrad.
--
-------------------------------------------------------------------------------
Konrad Hinsen | E-Mail: hinsen at cnrs-orleans.fr
Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24
Rue Charles Sadron | Fax: +33-2.38.63.15.17
45071 Orleans Cedex 2 | Deutsch/Esperanto/English/
France | Nederlands/Francais
-------------------------------------------------------------------------------
More information about the NumPy-Discussion
mailing list