补图#
- complement(G)[source]#
返回图 G 的补图。
- 参数:
- G图
一个 NetworkX 图
- 返回:
- GC一个新的图。
注意
注意,
complement
不会创建自环,对于 MultiGraph 也不会产生平行边。图、节点和边的属性数据不会传播到新图中。
示例
>>> G = nx.Graph([(1, 2), (1, 3), (2, 3), (3, 4), (3, 5)]) >>> G_complement = nx.complement(G) >>> G_complement.edges() # This shows the edges of the complemented graph EdgeView([(1, 4), (1, 5), (2, 4), (2, 5), (4, 5)]) ----