to_graph6_bytes#
- to_graph6_bytes(G, nodes=None, header=True)[source]#
将一个简单的无向图转换为 graph6 格式的字节串。
- 参数:
- G图 (无向)
- nodes: list 或 iterable (可迭代对象)
节点按提供的顺序编号为 0…n-1。如果为 None,则使用
G.nodes()
给出的顺序。- header: bool (布尔值)
如果为 True,则在数据开头添加 ‘>>graph6<<’ 字节。
- 引发的异常:
- NetworkXNotImplemented
如果图是有向图或多重图。
- ValueError
如果图至少有
2 ** 36
个节点;graph6 格式仅定义了节点数小于2 ** 36
的图。
另请参阅
from_graph6_bytes
,read_graph6
,write_graph6_bytes
说明
返回的字节串以换行符结尾。
此格式不支持边或节点标签、并行边或自环。如果存在自环,它们将被默默忽略。
参考资料
[1]Graph6 规范 <http://users.cecs.anu.edu.au/~bdm/data/formats.html>
示例
>>> nx.to_graph6_bytes(nx.path_graph(2)) b'>>graph6<<A_\n'