[英]'numpy.int64' object is not iterable
for i in Train.index :
preds = nx.jaccard_coefficient(G, ebunch = (Train['source_node'][i], Train['destination_node'][i]))
for u,v,p in preds:
print('(%d, %d) -> %.8f' % (u, v, p))
TypeError Traceback (most recent call last)
<ipython-input-23-95e128c1b501> in <module>()
3
4 preds = nx.jaccard_coefficient(G, ebunch = (Train['source_node'][i], Train['destination_node'][i]))
----> 5 for u,v,p in preds:
6 print('(%d, %d) -> %.8f' % (u, v, p))
C:\ProgramData\Anaconda3\lib\site-packages\networkx\algorithms\link_prediction.py in <genexpr>(.0)
136 return len(cnbors) / union_size
137
--> 138 return ((u, v, predict(u, v)) for u, v in ebunch)
139
140
TypeError: 'numpy.int64' object is not iterable
The argument ebunch
must be an iterable of tuples. ebunch
参数必须是一个可ebunch
的元组。 You haven't shown enough code for us to know what Train['source_node'][i]
and Train['destination_node'][i]
are, but based on the error message, I suspect they are numpy.int64
objects. 您没有显示足够的代码让我们知道Train['source_node'][i]
和Train['destination_node'][i]
是什么,但是基于错误消息,我怀疑它们是numpy.int64
对象。 In that case, you need to nest these one level further in the ebunch
argument. 在这种情况下,您需要将这些级别进一步嵌套在ebunch
参数中。 For example, here I set ebunch
to be a list containing a single tuple: 例如,在这里我将ebunch
设置为包含单个元组的列表:
preds = nx.jaccard_coefficient(G, ebunch = [(Train['source_node'][i], Train['destination_node'][i])])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.