简体   繁体   English

我有一段代码来运行回归,但我不知道为什么会出现语法错误。 下面的代码

[英]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.

相关问题 为什么在这段代码(Python)中出现无效的语法错误? - Why do I get an invalid syntax error in this piece of code, Python? 我有以下代码抛出和错误。 - I have the following code throwing and error. 为什么下面的代码有语法错误? - Why does the below code have a syntax error? 为什么我在这段代码中收到语法错误? - Why am I getting a syntax error in this piece of code? 为什么我在应用此代码时收到此错误。 我在下面附上了错误和代码? - Why I am getting this error while applying this code. I have enclosed the error and code below? 我有这段代码,试图通过捕获视频来运行社会隔离识别,但我有这个错误。 你可以帮帮我吗? - I have this code, trying to run a social isolation identification by capturing video, but I have this error. Could you help me? 当我在 Visual Studio Code 中编写编译代码时,我无法得到结果,我运行 python deploy.py,它给了我错误。 我必须在我的代码中编辑的内容 - I couldn't get results when I write compiled code in Visual Studio Code, I run python deploy.py and it gives me error. what I have to edit in my code 为什么我不能在下面代码的第一个函数中得到结果,但在第二个函数中得到它们没有问题? - why cant i get the result in the first function in the code below but have no issues getting them in the second one? EasyGUI缩进错误,我不知道为什么 - EasyGUI indent error, I have no idea why 一段 Python 代码中的算法错误 - 我不能做我必须做的事 - Algorithmic error in a piece of Python code - I can not do what I have to do
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM