会抛出一些错误,最后2行会抛出错误
import numpy as np
f=open('decision_tree_data.txt','r')
x_train=[]
y_train=[]
for line in f:
line = np.asarray(line.split(),dtype=np.float32)
x_train.append(line[:-1])
y_train.append(line[:-1])
x_train = np.asmatrix(x_train)
y_train = np.reshape(y_train,(len(y_train),1))
答案 0 :(得分:1)
检查代码的缩进。以下代码为我成功编译并确保已安装numpy模块。
import numpy as np
f=open('decision_tree_data.txt','r')
x_train=[]
y_train=[]
for line in f:
line=np.asarray(line.split(),dtype=np.float32)
x_train.append(line[:-1])
y_train.append(line[-1])
x_train=np.asmatrix(x_train)
y_train=np.reshape(y_train,(len(y_train),1))