小编Cha*_*hni的帖子

使用networkx(python)读取GML文件,不带节点标签

我有一个很长的GML文件(图形建模语言),我试图用Python中的Networkx阅读.在GML文件中,节点没有标签,如下所示:

graph [
  node [
    id 1
  ]
  node [
    id 2
  ]
  edge [
    source 2
    target 1
    ]
  ]
Run Code Online (Sandbox Code Playgroud)

我在读取文件时遇到错误:G = nx.read_gml('simple_graph.gml')

---------------------------------------------------------------------------
NetworkXError                             Traceback (most recent call last)
<ipython-input-39-b1b319a08668> in <module>()
----> 1 G = nx.read_gml('simple_graph.gml')

<decorator-gen-319> in read_gml(path, label, destringizer)

/usr/lib/python2.7/dist-packages/networkx/utils/decorators.pyc in _open_file(func, *args, **kwargs)
    218         # Finally, we call the original function, making sure to close the fobj.
    219         try:
--> 220             result = func(*new_args, **kwargs)
    221         finally:
    222             if close_fobj:

/usr/lib/python2.7/dist-packages/networkx/readwrite/gml.pyc in read_gml(path, label, …
Run Code Online (Sandbox Code Playgroud)

python networkx graph-modelling-language

2
推荐指数
1
解决办法
2853
查看次数