【发布时间】:2013-12-02 09:19:52
【问题描述】:
当我尝试计算列的平均值时,我不断收到“无法使用灵活类型执行 reduce”,文件被读取得很好(任何行/列中都没有缺失值)但是当我排队时: Brain_wt_mean = np.mean(ifile axis=0) 然后 Python 2.7.5 不喜欢它。我在 Spyder IDE 中使用它。非常感谢您的帮助。
import os
import numpy as np
if __name__ == "__main__":
try:
curr_dir = os.getcwd()
file_path = curr_dir + '\\brainandbody.csv'
ifile = np.loadtxt('brainandbody.csv', delimiter=',', skiprows=1, dtype=[('brainwt', 'f8'), ('bodywt', 'f8')])
except IOError:
print "The file does not exist, exiting gracefully"
Brain_wt_mean = np.mean(ifile axis=0)
### BELOW is a sample of the csv file ######
Brain Weight Body Weight
3.385 44.5
0.48 15.5
1.35 8.1
465 423
36.33 119.5
27.66 115
14.83 98.2
1.04 5.5
【问题讨论】:
-
有些逗号在复制粘贴后无法保存吗?您的示例不是逗号分隔的,但您的
loadtxt设置delimiter=','和ifile axis=0不是有效的 Python
标签: python-2.7 numpy scipy