(data_filename, meta_filename)
return np.asarray(data, dtype='float32'), meta['discrete_columns']
Read a tsv file.
Read a tsv file.
Read a tsv file .
def read_tsv(data_filename, meta_filename):
    """Read a tsv file."""
    with open(meta_filename) as f:
        column_info = f.readlines()

    column_info_raw = [
        x.replace('{', ' ').replace('}', ' ').split()
        for x in column_info
    ]

    discrete = []
    continuous = []
    column_info = []

    for idx, item in enumerate(column_info_raw):
        if item[0] == 'C':
            continuous.append(idx)
            column_info.append((float(item[1]), float(item[2])))
        else:
            assert item[0] == 'D'
            discrete.append(idx)
            column_info.append(item[1:])

    meta = {
        'continuous_columns': continuous,
        'discrete_columns': discrete,
        'column_info': column_info
    }

    with open(data_filename) as f:
        lines = f.readlines()

    data = []
    for row in lines:
        row_raw = row.split()
        row = []
        for idx, col in enumerate(row_raw):
            if idx in continuous:
                row.append(col)
            else:
                assert idx in discrete
                row.append(column_info[idx].index(col))

        data.append(row)

    return np.asarray(data, dtype='float32'), meta['discrete_columns']
def read_tsv ( data_filename , meta_filename ) : with open ( meta_filename ) as f : column_info = f . readlines ( ) column_info_raw = [ x . replace ( '{' , ' ' ) . replace ( '}' , ' ' ) . split ( ) for x in column_info ] discrete = [ ] continuous = [ ] column_info = [ ] for idx , item in enumerate ( column_info_raw ) : if item [ 0 ] == 'C' : continuous . append ( idx ) column_info . append ( ( float ( item [ 1 ] ) , float ( item [ 2 ] ) ) ) else : assert item [ 0 ] == 'D' discrete . append ( idx ) column_info . append ( item [ 1 : ] ) meta = { 'continuous_columns' : continuous , 'discrete_columns' : discrete , 'column_info' : column_info } with open ( data_filename ) as f : lines = f . readlines ( ) data = [ ] for row in lines : row_raw = row . split ( ) row = [ ] for idx , col in enumerate ( row_raw ) : if idx in continuous : row . append ( col ) else : assert idx in discrete row . append ( column_info [ idx ] . index ( col ) ) data . append ( row ) return np . asarray ( data , dtype = 'float32' ) , meta [ 'discrete_columns' ]