I'm at my wit's end as I keep getting "cannot perform reduce with flexible type" when I try to compute the mean of a column, the file is read in just fine (no missing values in any rows/column) but when I put in the line: Brain_wt_mean = np.mean(ifile axis=0) then Python 2.7.5 does not like it. I am using this within the Spyder IDE. Thanks much for any help.
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
setsdelimiter=','
, andifile axis=0
isn't valid Python – DSM