问题描述:

I'm trying to use the function "adamic_adar_index" in Python's networkx package. I'm following this example in the NetworkX documentation: https://networkx.github.io/documentation/latest/reference/generated/networkx.algorithms.link_prediction.adamic_adar_index.html

import networkx as nx

G = nx.complete_graph(5)

preds = nx.adamic_adar_index(G, [(0, 1), (2, 3)])

for u, v, p in preds:

'(%d, %d) -> %.8f' % (u, v, p)

The function returns a generator object named "preds", but for some reason, when I convert it to a list using list(preds), it returns an empty list. I'm trying to get a list of 3-tuples with each tuple in the form (u,v,p), but having some trouble actually getting it. Thanks!

网友答案:

Just add a print statement to your last line:

for u, v, p in preds:
    print '(%d, %d) -> %.8f' % (u, v, p)
相关阅读:
Top