Tôi gặp sự cố có vẻ như câu trả lời sẽ được giải thích một cách dễ dàng. Tôi đang phải vật lộn để chuyển đổi các phần tử mảng của tôi để nổi (vì vậy mà tôi có thể nhân lên, thêm vào chúng vv)Không thể chuyển đổi mảng thành phao python
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]
và tôi nhận được lỗi:
> --------------------------------------------------------------------------- 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
Bạn có thể xem mã của mình không? Nó không phù hợp với những gì trong ngoại lệ. Tôi thấy một vài khác biệt, bao gồm một số thụt đầu dòng. – Brionius
Bạn có thể hiển thị đầu ra của dòng 19 không? – Dschoni