本文整理汇总了Python中networkx.reverse方法的典型用法代码示例。如果您正苦于以下问题:Python networkx.reverse方法的具体用法?Python networkx.reverse怎么用?Python networkx.reverse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类networkx
的用法示例。
在下文中一共展示了networkx.reverse方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: shallow_reverse
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import reverse [as 别名]
def shallow_reverse(g):
"""
Make a shallow copy of a directional graph and reverse the edges. This is a workaround to solve the issue that one
cannot easily make a shallow reversed copy of a graph in NetworkX 2, since networkx.reverse(copy=False) now returns
a GraphView, and GraphViews are always read-only.
:param networkx.DiGraph g: The graph to reverse.
:return: A new networkx.DiGraph that has all nodes and all edges of the original graph, with
edges reversed.
"""
new_g = networkx.DiGraph()
new_g.add_nodes_from(g.nodes())
for src, dst, data in g.edges(data=True):
new_g.add_edge(dst, src, **data)
return new_g
示例2: __init__
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import reverse [as 别名]
def __init__(self, graph, entry_node, successors_func=None, reverse=False):
self._l = logging.getLogger("utils.graph.dominators")
self._graph_successors_func = successors_func
self._reverse = reverse # Set it to True to generate a post-dominator tree.
# Temporary variables
self._ancestor = None
self._semi = None
self._label = None
# Output
self.dom = None
self.prepared_graph = None
self._construct(graph, entry_node)
示例3: test_reverse1
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import reverse [as 别名]
def test_reverse1():
# Other tests for reverse are done by the DiGraph and MultiDigraph.
G1=nx.Graph()
assert_raises(nx.NetworkXError, nx.reverse, G1)
示例4: test_reverse1
# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import reverse [as 别名]
def test_reverse1():
# Other tests for reverse are done by the DiGraph and MultiDigraph.
G1 = nx.Graph()
assert_raises(nx.NetworkXError, nx.reverse, G1)