【发布时间】:2013-06-21 02:15:33
【问题描述】:
我正在尝试从文本文件中读取数据并取该数据的平均值,但我收到错误无法使用灵活类型执行 reduce。我不知道为什么,有人可以帮忙。这是我的代码。
right=open('01phi.txt','r').readlines()
right=str(right)
a=np.asarray(right)
b=np.mean(a)
print b
EDIT:我现在正在使用这一行
right=np.genfromtxt('01phi.txt')
但它会产生此错误Line #10 (got 3 columns instead of 7),因为数组中的这一行没有那么大。 Using genfromtxt to import csv data with missing values in numpy 这个链接告诉我如何忽略底线或如何填写底线,但这两种方法都会扼杀平均值。有没有办法解决这个问题?
【问题讨论】: