Tuesday, 15 January 2013

IndexError: string index out of range python, numpy -


Longer my hair is tearing out if I run an input file

  # 96,52 0,0036 # # 0,860 9,38 0,938 35 I 1.235 6.452 0.030 41 J 2MASS 1.66 5.471 0.021 42 H I_band 2MASS 2.16 5.069 0.023 43 K 2MASS 9.0 9.760e-01 8.51e-03 0 AKARI09 0.52 18.0 2.609 E-01 3.67e-02 0 AKARI18 0.52 #   

I

  file 'myfile.py', line 811, & lt; Module & gt;   

However, if I run

  # 96,52,036 ###8609383893835 I I_band 1.235 6.452 0.030 41 J 2MASS 0,134 1,66 5,471 0,021 42 H2MASS 0,134 2,16 5,069 0,023 43 K 2MASS 0.134 9.0 9.760e-01 8.51e-03 0 AKARI09 0.52 18.0 2.609e-01 3.67e -02 0 AKARI18 0.52 #   

The code should do this work. Both of those examples are saved as a .at file, which is prompted to direct me to the code.

I'm trying to understand it for 24 hours (I know, right?) No success at all. Any advice at this point I can not solve my problem will be welcomed as always!

EDIT: If I change the XRANG for the 'range' (around the 800 line) and return to add (see lines 792 and 798) I will get this error now :

  The file 'myfile.py', line 807, & lt; Module & gt; If (data [i] == '#'): Comments = comments + 1 index error: list index out of range    

I do not have the time to follow my code through 1000+ lines (and I have many doubts). But whatever I can see, you try to change the wheel again as a way to read your files. You are getting an error because your column does not have type / size near your data array

I suggest getting acquainted with nodi or functions. You might find most of the data in the file format that you want with a single call. (All the open calls in your code are in binary, so I do not know how the text file enters.) I do not know what your format is, but for example you do something like this:

 Import code as np result = np.genfromtxt ('file', numpy dtype = [('wave', 'f'), ('flow', 'f'), ('' a '', 'f'   

The result is structured array ('code', 'i'), ('band', 's8'), ('survey', 's8')] Which you can do dtype by wire index:

  in [16]: results ['wave'] out [16]: array ([0.8660,001, 1.2,35,00,001 [17]: array ([0.93800002, 0.03 [18]: Results ['band'] outside [18]: array (['I', 'J', 'H', 'K'], [18]: [18] , 'AKARI09', 'AKARI18'], dtype = '| S8')   

Here I saved the last column as a string, so you have to convert numbers into the previous two rows May be.

No comments:

Post a Comment