[SciPy-user] loadtxt error

Dharhas Pothina Dharhas.Pothina@twdb.state.tx...
Wed Apr 23 09:31:06 CDT 2008


I'm trying to transition from matlab to scipy/numpy and am having problems with things that should be fairly straightforward.

I have an ascii text file with the format :

year month sumprcp(in)
1976 01 2.07
1976 02 0.76
1976 03 2.53
1976 04 2.25

When trying to read it with the function loadtxt() I am getting an error :
in iPython I type :

from numpy import *
year,month,data = loadtxt('portarthurcity_monthlyprecip.txt',skiprows=1,unpack=True)

I get the error :

ValueError                                Traceback (most recent call last)

/home/dharhas/projects/sabine-neches/keithlake/analysis/hydrology/<ipython console> in <module>()

/usr/lib64/python2.5/site-packages/numpy/core/numeric.py in loadtxt(fname, dtype, comments, delimiter, converters, skiprows, usecols, unpack)
    723         X.append(row)
--> 725     X = array(X, dtype)
    726     r,c = X.shape
    727     if r==1 or c==1:

ValueError: setting an array element with a sequence.

Am I doing something basic wrong? Variations of the function call with a file without header lines etc give the same error.


- dharhas

More information about the SciPy-user mailing list