【发布时间】:2020-11-15 04:01:18
【问题描述】:
networkx tutorial 暗示了添加具有属性的节点的可能性。
如果您的容器产生
(node, node_attribute_dict)形式的 2 元组,您还可以添加节点以及节点属性
当我尝试使用 add_node 方法时,我得到一个 TypeError:
>>> import networkx as nx
>>> G = nx.Graph()
>>> G.add_node(('person1', {'name': 'John Doe', 'age': 40}))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/media/windows/Users/godidier/Projects/semlab/research/env/lib/python3.7/site-packages/networkx/classes/graph.py", line 506, in add_node
if node_for_adding not in self._node:
TypeError: unhashable type: 'dict'
我错过了什么?还是只能使用add_nodes_from 方法添加具有属性的节点?
【问题讨论】: