def ReadMatrix(file,
               separator="\t",
               numeric_type=numpy.float,
               take="all",
               headers=False
               ):

    lines = filter(lambda x: x[0] != "#", file.readlines())

    row_headers, col_headers = [], []

    if headers:
        col_headers = lines[0][:-1].split("\t")[1:]
        del lines[0]

    num_rows = len(lines)

    if take != "all":
        num_cols = len(take)
    else:
        l = len(string.split(lines[0][:-1], "\t"))
        if headers:
            take = range(1, l)
        else:
            take = range(0, l)

    num_cols = len(take)

    matrix = numpy.zeros((num_rows, num_cols), numeric_type)

    nrow = 0
    for l in lines:
        data = l[:-1].split("\t")
        if headers:
            row_headers.append(data[0])

        try:
            data = map(lambda x: float(data[x]), take)
        except ValueError:
            print "error parsing data", data
            raise

        matrix[nrow] = data
        nrow += 1

    return matrix, row_headers, col_headers
read a matrix. There probably is a routine for this in Numpy, which
dataset/ETHPy150Open CGATOxford/cgat/CGAT/MatlabTools.py/ReadMatrix