to_sparse6_bytes#
- to_sparse6_bytes(G, nodes=None, header=True)[源]#
将无向图转换为 sparse6 格式的字节串。
- 参数:
- G图 (无向图)
- nodes: 列表或可迭代对象
节点按照提供的顺序标记为 0…n-1。如果为 None,则使用
G.nodes()
给出的顺序。- header: 布尔值
如果为 True,则在数据头部添加 ‘>>sparse6<<’ 字节。
- 引发:
- NetworkXNotImplemented
如果图是有向图。
- ValueError
如果图至少有
2 ** 36
个节点;sparse6 格式仅定义用于节点数小于2 ** 36
的图。
另请参阅
to_sparse6_bytes
,read_sparse6
,write_sparse6_bytes
说明
返回的字节串以换行符结尾。
此格式不支持边或节点标签。
参考资料
[1]Graph6 规范 <https://users.cecs.anu.edu.au/~bdm/data/formats.html>
示例
>>> nx.to_sparse6_bytes(nx.path_graph(2)) b'>>sparse6<<:An\n'