Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.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
Python:ValueError:操作数无法与形状一起广播(101)(2)_Python_Numpy - Fatal编程技术网

Python:ValueError:操作数无法与形状一起广播(101)(2)

Python:ValueError:操作数无法与形状一起广播(101)(2),python,numpy,Python,Numpy,运行下面显示的代码时,我收到以下错误消息:“ValueError:操作数无法与形状(101)(2)一起广播” 全文如下: Traceback (most recent call last): File "/Users/Bob/Desktop/MachineLearning/machLearn.py", line 47, in <module> ppn.fit(X,y) File "/Users/Bob/Desktop/MachineLearning/machLearn

运行下面显示的代码时,我收到以下错误消息:“ValueError:操作数无法与形状(101)(2)一起广播”

全文如下:

Traceback (most recent call last):
  File "/Users/Bob/Desktop/MachineLearning/machLearn.py", line 47, in <module>
    ppn.fit(X,y)
  File "/Users/Bob/Desktop/MachineLearning/machLearn.py", line 18, in fit
    self.w_[1:] += update * xi
ValueError: operands could not be broadcast together with shapes (101) (2) 
[Finished in 0.8s with exit code 1]

注意:上面的代码示例来自Python机器学习(Sebastian Raschka,2015,第26页)

self.w_[1:
具有大小
X.shape[1]
,我假设是
102
,而
xi
将具有大小
X.shape[0]
,我认为是
2

您可能要更改此行:

for xi, target in zip(X, y):


这将给出
xi
X.shape[1]以匹配
self.w_[1:][/code>

这三个项目中的一个
self.w_[1:],更新,xi
具有形状(101,),另一个是(2,)-即一个项目中有101个,另一个项目中有2个。哪些数字有意义?您可能需要验证这一点。
for xi, target in zip(X, y):
for xi, target in zip(X.T, y):