我得到了这个错误:
ValueError: operands could not be broadcast together with shapes (2,5) (5,2) 我不知道哪里出了问题。顺便说一句,这个问题要求我们找到w作为最终的ans。关于应该做什么有什么建议吗?
以下是代码:
import numpy as np
def A1_number(X, y):
XT = np.transpose(X)
#print(XT)
InvXTX = np.linalg.inv(XT*X)
#print(InvXTX)
Xt = (InvXTX)*XT
#print(Xt)
InvXtX = np.linalg.inv(Xt*X)
w = InvXtX*(Xt*y)
#return w
# return in this order
return InvXTX, w
print(A1_number([[1,2],[3,4],[5,6],[7,8],[9,10]], [0,0,1,0,0]))发布于 2020-09-06 06:02:05
看起来您要传递的值是关闭的;因此出现了值错误。
A= [[1,2],[3,4],[5,6],[7,8],[9,10], [missing second array]]
B= [[0,0,1,0,0], [missing array]]
希望能帮上忙。
https://stackoverflow.com/questions/63761124
复制相似问题