python - numpy loadtxt IndexError: list index out of range -
i'm newbie python , have text file looks this:
# wed 13:10:08 11-mar-2015 begin aperture image1 1 1024. 139.7445 image image1 aperture 1 beam 1 center 1024. 139.7445 low -1023. -4. high 1024. 4. background xmin -40.45428 xmax 43.75221 function chebyshev order 3 sample -40.45428:-18.42313 20.09063:43.75221 naverage 1 niterate 0 low_reject 3. high_reject 3. grow 0. axis 2 curve 6 2. 2. 4. 2044. -0.1275881 -0.03320996
i want extract '139.7445' sixth row ('center'). code:
pos_wasp = np.loadtxt(line, skiprows=5, usecols=(3,4), unpack=true)
but when run it, gives error:
indexerror: list index out of range
it should simple problem solve , i've been trying change column numbers , data types many times, still doesn't work.
i think code failing because loadtxt
wants read in lines after 1 value on. 1 value, why not read file (inpp.txt
, or whatever yours called) directly:
with open('inpp.txt') fi: line in fi: fields = line.split() if fields[0] == 'center': val = float(fields[2]) break print(val)
Comments
Post a Comment