[SciPy-user] loadtxt error

Nils Wagner nwagner at iam.uni-stuttgart.de
Wed Apr 23 10:44:16 EDT 2008


On Wed, 23 Apr 2008 09:31:06 -0500
  "Dharhas Pothina" <Dharhas.Pothina at twdb.state.tx.us> 
wrote:
> Hi,
> 
> 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)
>    724 
> --> 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.
> 
> thanks.
> 
> - dharhas
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user

No problem here.

In [1]: run test_load.py

In [2]: year
Out[2]: array([ 1976.,  1976.,  1976.,  1976.])

In [3]: month
Out[3]: array([ 1.,  2.,  3.,  4.])

In [4]: data
Out[4]: array([ 2.07,  0.76,  2.53,  2.25])

In [5]: import numpy

In [6]: numpy.__version__
Out[6]: '1.1.0.dev5070'

Nils

  



More information about the SciPy-User mailing list