network API: read_adjlist
Read graph in adjacency list format from path.

Parameters: 
path (string or file) – Filename or file handle to read. Filenames ending in .gz or .bz2 will be uncompressed.
create_using (NetworkX graph container) – Use given NetworkX graph for holding nodes or edges.
nodetype (Python type, optional) – Convert nodes to this type.
comments (string, optional) – Marker for comment lines
delimiter (string, optional) – Separator for node labels. The default is whitespace.
create_using – Use given NetworkX graph for holding nodes or edges.

邻接表形式读取图。

  • path可以是文件句柄;
  • create_using用已有G创建。

例子:

G=nx.path_graph(4)
nx.write_adjlist(G, "test.adjlist")
G = nx.read_adjlist("test.adjlist")
G.edges

EdgeView([(‘0’, ‘1’), (‘1’, ‘2’), (‘2’, ‘3’)])

  • 所有节点类型变为int型
G=nx.read_adjlist("test.adjlist", nodetype=int)
  • create_using参数表示NetworkX graph container. 默认是Graph(), 一个无向图. 以有向图读取:
G=nx.read_adjlist("test.adjlist", create_using=nx.DiGraph())
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/NockinOnHeavensDoor/article/details/80317547
个人分类: networkx
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

network API: read_adjlist

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭