我遇到了一个问题,似乎答案很容易解释。我正在努力将我的数组元素转换为浮点数(以便我可以乘以,添加它们等)
import csv
import os
import glob
import numpy as np
def get_data(filename):
with open(filename, 'r') as f:
reader = csv.reader(f)
return list(reader)
all_data = []
path=raw_input('What is the directory?')
for infile in glob.glob(os.path.join(path, '*.csv')):
all_data.extend(get_data(infile))
a = np.array(all_data)
current_track_data=a[0:,[8,9,10,11,12]]
abs_track_data=a[0:,7]
我得到了错误:
> --------------------------------------------------------------------------- ValueError Traceback (most recent call last) C:\Users\AClayton\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.0.3.1262.win-x86_64\lib\site-packages\IPython\utils\py3compat.pyc in execfile(fname, glob, loc)
174 else:
175 filename = fname
--> 176 exec compile(scripttext, filename, 'exec') in glob, loc
177 else:
178 def execfile(fname, *where):
>
> C:\Users\AClayton\Current\python begin\code_tester2.py in <module>()
> 18 for infile in glob.glob(os.path.join(path, '*.csv')): # performs loop for each file in the specified path with extension .csv
> 19 all_data.extend(get_data(infile))
> ---> 20 a = np.ndarray(all_data, dtype=float)
> 21
> 22 current_track_data=a[0:,[8,9,10,11,12]]
>
> ValueError: sequence too large; must be smaller than 32