[SciPy-User] How To Use Loadtxt For Floats And Strings?

Pierre GM pgmdevlist@gmail....
Sat Jun 12 12:31:40 CDT 2010


On Jun 12, 2010, at 12:55 PM, Joseph Smidt wrote:
> a, b, c = loadtxt('myfile.txt',unpack=True,dtype=(float,float,'S16'))
> 
> I must be doing something wrong.  What is the proper expression for
> loadtxt?  Or must I use something else?  Thanks!

The right side outputs 1 structured array with field names 'f0','f1' and 'f2' by default. 
You can access individual columns by
>>> tmp =  loadtxt('myfile.txt',unpack=True,dtype=(float,float,'S16'))
>>> (a,b,c) = [tmp["f%i" % i] for i in (0,1,2)]

or something like that



More information about the SciPy-User mailing list