我有一个 networkx 图对象,它是加权的和无向的。我正在尝试使用 Adamic Adar 索引为每个节点预测 10 个新链接。Networkx 中的函数adamic_adar_index 返回元组的生成器,其格式为(nodeid1, nodeid2,adamic_adar_index)。我不熟悉 Python 中的生成器。我想要做的是按 nodeid1 对生成器进行分组,并为 nodeid1 返回最大的 10 个索引。
这是我的代码,其中“coauthor”是网络对象,“preds”是生成器。数据文件在这里https://www.dropbox.com/s/hyr1hgjs4yt03x2/coauthor.csv?dl=0
import csv
import networkx as nx
g = nx.read_weighted_edgelist("coauthor.csv", delimiter='\t', encoding='utf-8')
coauthor = nx.read_weighted_edgelist("coauthor.csv", delimiter='\t', encoding='utf-8')
preds = nx.adamic_adar_index(coauthor)
Run Code Online (Sandbox Code Playgroud) 我想获取特定存储库的贡献者及其提交总数。我正在使用 Python 2.7 和 Requests 2.7.0 库来请求 GitHub API url,例如:“ https://api.github.com/repos/marcboeker/mongodb-utils/stats/contributors ”(这是一个随机链接,抱歉马克布克^_^)。
然而,当我第一次请求特定的 url 时,我得到了一个空的字典响应。第二次请求相同的 url 时,我可以获得包含我需要的信息的列表。这是我的代码:
import requests
contributors_url = 'https://api.github.com/repos/marcboeker/mongodb-utils/stats/contributors'
contributors = requests.get(contributors_url).json()
print contributors
Run Code Online (Sandbox Code Playgroud)
我还尝试使用 GitHub 身份验证并尝试使用 urllib2 库。我也在Python 3.4中尝试过。但我得到了同样的结果。我需要在第一次请求 URL 时获得正确的结果,而不是第二次或第三次。由于其他 GitHub API url 工作正常,请解释为什么它会发生在“贡献者”身上。

