差异#

difference(G, H)[源代码]#

返回一个新图表,其中包含存在于g中但不存在于h中的边。

H和G的节点集必须相同。

参数
G,H图表

网络X图。G和H必须具有相同的节点集。

返回
D给出了与G.

笔记

图中的属性、节点和边不会复制到新图中。如果需要具有G中的属性(包括边数据)的G和H的差值的新图形,请使用Remove_Nodes_from(),如下所示:

>>> G = nx.path_graph(3)
>>> H = nx.path_graph(5)
>>> R = G.copy()
>>> R.remove_nodes_from(n for n in G if n in H)

实例

>>> G = nx.Graph([(0, 1), (0, 2), (1, 2), (1, 3)])
>>> H = nx.Graph([(0, 1), (1, 2), (0, 3)])
>>> R = nx.difference(G, H)
>>> R.nodes
NodeView((0, 1, 2, 3))
>>> R.edges
EdgeView([(0, 2), (1, 3)])