【发布时间】:2020-05-05 14:47:39
【问题描述】:
我是 Python 和 NetworkX 的新手,我正在尝试将字典中的属性提供给使用图形生成器创建的网络节点。这是我的示例代码:
g = nx.watts_strogatz_graph(5,4,0.1)
name_dict = {
0: "Alice",
1: "Bob",
2: "Carl",
3: "Diana",
4: "Elain",
}
nx.set_node_attributes(g, name, name_dict)
但是我收到以下错误:
nx.set_node_attributes(g, name, name_dict)
NameError: name 'name' is not defined
如何定义从字典中给出值的属性名称('name')?
【问题讨论】:
标签: python networkx graph-theory