import numpy as np
#read in data and extract columns
cols = np.loadtxt('CST210.txt')
Day1Attendence = cols[:,0]
Day2Attendence = cols[:,1]
#calculate the total attendence over the two days
TotalAttendence = Day1Attendence + Day2Attendence
#create second array from Day1Attendence and Day2Attendence
outArray = np.column_stack((Day1Attendence,Day2Attendence))
#save to test file
np.savetxt('Totalattandence.txt',outArray, delimiter = 'A')
这是我得到的错误代码
runfile('/ home / kasey / Documents / module1code.py', wdir ='/ home / kasey / Documents')追溯(最近一次通话过去):
文件“”,第1行,在 runfile('/ home / kasey / Documents / module1code.py',wdir ='/ home / kasey / Documents')
文件 “ /opt/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py”, 运行文件中的第668行 execfile(文件名,命名空间)
文件 “ /opt/anaconda3/lib/python3.7/site-packages/spyder_kernels/customize/spydercustomize.py”, execfile中的第108行 exec(compile(f.read(),文件名,'exec'),命名空间)
文件“ /home/kasey/Documents/module1code.py”,第13行,在 cols = np.loadtxt('CST210.txt')
文件 “ /opt/anaconda3/lib/python3.7/site-packages/numpy/lib/npyio.py”,行 1101,在loadtxt中 对于read_data(_loadtxt_chunksize)中的x:
文件 “ /opt/anaconda3/lib/python3.7/site-packages/numpy/lib/npyio.py”,行 1028,在read_data中 items = [zip(converters,vals)中的(conv,val)的conv(val)]
文件 “ /opt/anaconda3/lib/python3.7/site-packages/numpy/lib/npyio.py”,行 1028,在 items = [zip(converters,vals)中的(conv,val)的conv(val)]
文件 “ /opt/anaconda3/lib/python3.7/site-packages/numpy/lib/npyio.py”,行 746,在floatconv中 返回float(x)
ValueError:无法将字符串转换为float:'“”“'