缺少参数错误,但给出了一个
我有一个无监督学习课程,其中一个功能似乎无缘无故地抛出错误。我抛出错误的类方法是:
def flatten(self,cluster):
out = []
for item in cluster:
if isinstance(item, (list, tuple)):
out.extend(HC.flatten(item))
else:
out.append(item)
return out
这是我在网上找到的一个函数,它的参数是一个列表并将其展平,作为参数输入的列表的输出直到列表似乎抛出了错误以及所述错误:
[Running] python -u "c:\Users\benti\Group Project 2\HC\Complete Linkage.py"
(51, 98)
(343, 390)
(150, 317)
(7, 209)
(173, 235)
(11, 85)
((343, 390), 82)
Traceback (most recent call last):
File "c:\Users\benti\Group Project 2\HC\Complete Linkage.py", line 88, in <module>
Z= HC.run2()
File "c:\Users\benti\Group Project 2\HC\Complete Linkage.py", line 82, in run2
cluster2 = HC.flatten(cluster2)
File "c:\Users\benti\Group Project 2\HC\Super.py", line 170, in flatten
out.extend(HC.flatten(item))
TypeError: flatten() missing 1 required positional argument: 'cluster'
[Done] exited with code=1 in 8.745 seconds
我应该注意我正在使用超类并且没有在该类中抛出此错误。
I have a unsuperivsed learning class and one of the functions is throwing an error for seemingly no reason. My class method that's throwing the error is:
def flatten(self,cluster):
out = []
for item in cluster:
if isinstance(item, (list, tuple)):
out.extend(HC.flatten(item))
else:
out.append(item)
return out
Which is a function I have found online,its aruement is a list and it flattens it, the output of the lists that are being entered as the argument up to the list which seems to be throwing the error along with the stated error:
[Running] python -u "c:\Users\benti\Group Project 2\HC\Complete Linkage.py"
(51, 98)
(343, 390)
(150, 317)
(7, 209)
(173, 235)
(11, 85)
((343, 390), 82)
Traceback (most recent call last):
File "c:\Users\benti\Group Project 2\HC\Complete Linkage.py", line 88, in <module>
Z= HC.run2()
File "c:\Users\benti\Group Project 2\HC\Complete Linkage.py", line 82, in run2
cluster2 = HC.flatten(cluster2)
File "c:\Users\benti\Group Project 2\HC\Super.py", line 170, in flatten
out.extend(HC.flatten(item))
TypeError: flatten() missing 1 required positional argument: 'cluster'
[Done] exited with code=1 in 8.745 seconds
I should note I'm using a superclass and am not getting this error thrown within that class.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您想要一个静态方法,请从方法签名中删除
self
参数Looks like you want a static method, remove the
self
argument from the method signature