【发布时间】:2018-07-03 08:59:27
【问题描述】:
我不明白为什么我在行出现缩进错误 对于范围内的 c(0,num_labels): 我正在使用 python 3.6 和 scipy。 代码如下:
from lrcostfunction import lrcostfunction
from gradient import gradient
import numpy as np
from scipy import optimize
def onevsall(X,y,num_labels):
m = np.size(X,0)
n = np.size(X,1)
all_theta = np.zeros((num_labels,n+1))
X = np.insert(X,0,1,axis = 1)
for c in range(0, num_labels):
initial_theta = np.zeros((n+1,))
theta =
optimize.fmin_cg(lrcostfunction,initial_theta,fprime=gradient, args =
args)
np.insert(all_theta,c,theta,axis = 0)
return all_theta
【问题讨论】:
-
此代码不应产生缩进错误,但
theta =是语法错误。请确保在执行代码时准确地粘贴代码。我会说“检查标签!”但 Python 3 会产生不同的错误消息。 -
尽可能发布完整的堆栈跟踪
-
您可能正在混合使用空格和制表符
标签: python-3.x numpy machine-learning scipy