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