本文整理汇总了Python中networkx.classes.graph.Graph.delete_node方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.delete_node方法的具体用法?Python Graph.delete_node怎么用?Python Graph.delete_node使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx.classes.graph.Graph
的用法示例。
在下文中一共展示了Graph.delete_node方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_node
# 需要导入模块: from networkx.classes.graph import Graph [as 别名]
# 或者: from networkx.classes.graph.Graph import delete_node [as 别名]
def delete_node(self, n):
try:
if len(self.adj[n])==1: # allowed for leaf node
Graph.delete_node(self,n)
else:
raise NetworkXError(
"deleting interior node %s not allowed in tree"%(n))
except KeyError: # NetworkXError if n not in self
raise NetworkXError("node %s not in graph"%n)
示例2: delete_edge
# 需要导入模块: from networkx.classes.graph import Graph [as 别名]
# 或者: from networkx.classes.graph.Graph import delete_node [as 别名]
def delete_edge(self, u, v=None):
if v is None: (u,v)=u
if self.degree(u)==1 or self.degree(v)==1: # leaf edge
Graph.delete_edge(self,u,v)
else: # interior edge
raise NetworkXError(\
"deleting interior edge %s-%s not allowed in tree"%(u,v))
if self.degree(u)==0: # OK to delete remaining isolated node
Graph.delete_node(self,u)
if self.degree(v)==0: # OK to delete remaining isolated node
Graph.delete_node(self,v)