how can I get the gap colum in python?
Question: the log format is like that 100 0 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1
11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26
1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1

And I write python code,

    
    
    def read_data(filename, sep=" ", filt=int):
    
        def split_line(line):
            return line.split(sep)
    
        def apply_filt(values):
            return map(filt, values)
    
        def process_line(line):
            return apply_filt(split_line(line))
    
        f = open(filename)
        lines = map(process_line, f.readlines())
        # "[1]" below corresponds to x0
        X = np.array([ l[3:] for l in lines])
        # "or -1" converts 0 values to -1
        Y = np.array([l[1] or -1 for l in lines])
        f.close()
    
        return X, Y
    

X are getted from 3 colums,and Now I want to get every gap colum from the
third colums,how can I change the code,and the X will be 1 1 1 1 1 1 1 1 1 1 Y
are getted l[1] or -1.But I want to get 1 if l1 is greater than 0,and get -1
if l1 is equal to 0.How can I change it again?


Answer: I'm going to guess you want something like this:

    
    
    import numpy as np
    try:
        from cStringIO import StringIO
    except:
        from StringIO import StringIO
    
    def read_data(f, sep=" ", filt=int):
    
        def split_line(line):
            return line.split(sep)
    
        def apply_filt(values):
            return map(filt, values)
    
        def process_line(line):
            return apply_filt(split_line(line))
    
        #f = open(filename)
        lines = np.array(map(process_line, f.readlines()), dtype=int)
        # "[1]" below corresponds to x0
        X = lines[:,3::2]
        # "or -1" converts 0 values to -1
        Y = lines[:,:]    
        Y[Y<=0]=-1
    
        f.close()
    
        return X, Y
    
    
    reader = StringIO('100 0 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1\n')    
    
    
    x,y = read_data(reader)
    reader.close
    
    print 'X:', x
    print 'Y:', y
    

which gives:

    
    
    X: [[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]]
    Y: [[100  -1  -1   1   1   1   2   1   3   1   4   1   5   1   6   1   7   1
        8   1   9   1  10   1  11   1  12   1  13   1  14   1  15   1  16   1
       17   1  18   1  19   1  20   1  21   1  22   1  23   1  24   1  25   1
       26   1  27   1  28   1  29   1  30   1  31   1  32   1  33   1  34   1
       35   1]]
    

