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))
答案 0 :(得分:0)
其中有一个@
符号,Python会忽略它作为装饰器。您是说*
还是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))
打印90.03281689585363
。