文本文件如下所示:
david weight_2005 50
david weight_2012 60
david height_2005 150
david height_2012 160
mark weight_2005 90
mark weight_2012 85
mark height_2005 160
mark height_2012 170
如何计算大卫的体重和身高平均值并标记如下:
david>> mean(weight_2005 and weight_2012), mean (height_2005 and height_2012)
mark>> mean(weight_2005 and weight_2012), mean (height_2005 and height_2012)
我不完整的代码是:
import numpy as np
import csv
with open ('data.txt','r') as infile:
contents = csv.reader(infile, delimiter=' ')
c1,c2,c3 = zip(*contents)
data = np.array(c3,dtype=float)
那么如何申请 np.mean??