Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Numpy VALUERROR:操作数无法与形状(2,5)(5,2)一起广播_Numpy - Fatal编程技术网

Numpy VALUERROR:操作数无法与形状(2,5)(5,2)一起广播

Numpy VALUERROR:操作数无法与形状(2,5)(5,2)一起广播,numpy,Numpy,我得到这个错误: ValueError: operands could not be broadcast together with shapes (2,5) (5,2) 我不知道哪里出了问题。顺便说一句,这个问题要求我们找到w作为最终答案。关于应该做什么有什么建议吗 代码如下: import numpy as np def A1_number(X, y): XT = np.transpose(X) #print(XT) InvXTX = np.linalg.inv(

我得到这个错误:

ValueError: operands could not be broadcast together with shapes (2,5) (5,2) 
我不知道哪里出了问题。顺便说一句,这个问题要求我们找到
w
作为最终答案。关于应该做什么有什么建议吗

代码如下:

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]))

看起来您传递的值已关闭;因此出现值错误

  • 5 x 2
A=
[[1,2],[3,4],[5,6],[7,8],[9,10],[missing second array]]

  • 2 x 5
B=
[[0,0,1,0,0],[缺少数组]]

希望能有所帮助