以通用换行模式打开文件?

时间:2019-02-27 19:47:33

标签: python csv terminal perceptron

我目前正在为感知器编写代码,该代码可在三个维度上绘制数据。我在终端中运行它,并且在运行代码时收到此错误:

    Traceback (most recent call last):
File "perceptron2.py", line 70, in <module>
for row in csv_reader:
_csv.Error: new-line character seen in unquoted field - do you need to open the 
file in universal-newline mode?

在我的代码的第70行附近,我认为发生错误的区域是在下面的代码块中,在该代码块中,从x获取输入数据,并从y获取标签

X = np.zeros(shape=(80,2))
y = np.zeros(shape=(80,1))
z = np.zeros(shape=(80,0))
with open('joy.csv') as csv_file:
    csv_reader = csv.reader(csv_file, delimiter=',')
    line_count = 0
    for row in csv_reader:
        X[line_count] = [eval(row[0]), eval(row[1])]
        y[line_count] = [eval(row[2])]
        z[line_count] = [eval(row[3])]
        line_count += 1
        if line_count == 80:
            break

无论如何,我想知道是否有人知道我可以实施以解决我的问题的解决方案。谢谢!

0 个答案:

没有答案