[英]I have a piece of code to run regression but I have no idea why I get a syntax error. the code below
def computeCost(X,y,theta): tobesummed = np.power(((X @ theta.T)-y),2) # he yells invalid syntax no idea why return np.sum(tobesummed)/(2 * len(X))
There's an @
symbol in there that Python ignores as a decorator.那里有一个@
符号,Python 将其作为装饰器忽略。 Did you mean *
or maybe X.dot(theta.T)
?你是说*
还是X.dot(theta.T)
?
import numpy as np
def computeCost(X,y,theta):
tobesummed = np.power(((X * theta.T)-y),2)
return np.sum(tobesummed)/(2 * len(X))
X, y, theta = np.random.randn(1,10), np.random.randn(1,10), np.random.randn(1,10)
print(computeCost(X, y, theta))
prints 90.03281689585363
.打印90.03281689585363
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.