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))
其中有一个@
符号,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
。