gpt4 book ai didi

python - 访问 networkx 节点和属性

转载 作者:太空狗 更新时间:2023-10-30 02:34:12 29 4
gpt4 key购买 nike

我有这个 GraphML 文件,我已将其读入 Networkx。

所以我通过以下方式访问所有节点:

g.nodes()

它给了我一个字符串列表。假设其中之一是“123”。然后我尝试访问一个节点:

g["123"]

它给了我一本字典。

然后我尝试使用节点函数访问节点,如下所示:

for n in g.nodes( data = True ):
print n

然后它给了我一个二元组,其中字符串节点名称作为第一个元素,字典作为第二个元素。

问题是,它是一本与第一本不同的字典。这让我很困惑,所以这里的任何帮助都非常感谢。

它们应该不同吗?如果是这样,为什么?如果没有,那我做错了什么? :)如果有帮助,我可以发布实际数据。

最佳答案

您是否考虑过阅读 variousdocumentation

nlist : list

A list of nodes. If data=True a list of two-tuples containing (node, node data dictionary).

和...

adj_dict : dictionary

The adjacency dictionary for nodes connected to n.

“节点数据字典”和“邻接字典”不是一回事。

关于python - 访问 networkx 节点和属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9645087/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com