def read_csv(filename, delimiter=',', skiprows=1, dtype=float): def iter_func(): with open(filename, 'r') as infile: for _ in range(skiprows): next(infile) for line in infile: line = line.rstrip().split(",") for item in line: yield dtype(item) read_csv.rowlength = len(line) data = np.fromiter(iter_func(), dtype=dtype) data = data.reshape((-1, read_csv.rowlength)) return data