[Tutor] reading data

chris Hynes cjhynes36 at hotmail.com
Thu Jul 23 19:53:21 CEST 2009


I have a data file in which the first line is made up of words. Here is the original data file:

#Column density-scaled with production rate 3.16227766016838e+25
-10.0000 0.000e+00  0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 
-9.9000 0.000e+00  0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 0.000e+00 

I'd like to my program to skip any lines that begin with words and move on to lines that contain numbers. Right now I just cheat and delete the first line and resave the data file, but I was hoping that I could avoid these types of things in the future. Here is my code for reading the file and figuring out how many rows and columns to dimensionalize my array, then I read the data into the array:

from numpy import *
row=0
columnindex=0
x=open('halfmethanol.col','rt')
for line in x.readlines(): 
    data=line.split()
    columnindex=len(data)
    row=row+1
temp=ones((row,columnindex))
row=0
x=open('halfmethanol.col','rt')
for line in x.readlines():
    data=line.split()
    for column in range(columnindex):
        temp[row,column]=data[column]
    row=row+1

_________________________________________________________________
Windows Live™ SkyDrive™: Store, access, and share your photos. See how.
http://windowslive.com/Online/SkyDrive?ocid=TXT_TAGLM_WL_CS_SD_photos_072009
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090723/be1d7a0a/attachment.htm>


More information about the Tutor mailing list