""" Ex 5.14 from A Primer on ... 1. Read line by line 2. Split and convert to float 3. append to list 4. convert to arrays (optional) """ import numpy as np import matplotlib.pyplot as plt x_list = [] y_list = [] with open('xy.txt','r') as infile: for line in infile: words = line.split() x_list.append(float(words[0])) y_list.append(float(words[1])) """ Not strictly needed to convert to arrays, but makes subsequent calculations more efficient. """ x = np.array(x_list) y = np.array(y_list) print(f'Mean(y) = {np.mean(y_list)}, max = {np.max(y)}, min = {np.min(y)}') plt.plot(x,y) plt.show() """ Terminal> python read2columns.py Mean(y) = 0.0, max = 0.9482, min = -0.9482 """