Returns the reverse of the graph. The reverse is a graph with the same nodes and edges but with the directions of the edges reversed. Parameters ---------- copy : bool optional (default=True) If True, return a new DiGraph holding the reversed edg
(self, copy=True)
| 1342 | return G |
| 1343 | |
| 1344 | def reverse(self, copy=True): |
| 1345 | """Returns the reverse of the graph. |
| 1346 | |
| 1347 | The reverse is a graph with the same nodes and edges |
| 1348 | but with the directions of the edges reversed. |
| 1349 | |
| 1350 | Parameters |
| 1351 | ---------- |
| 1352 | copy : bool optional (default=True) |
| 1353 | If True, return a new DiGraph holding the reversed edges. |
| 1354 | If False, the reverse graph is created using a view of |
| 1355 | the original graph. |
| 1356 | """ |
| 1357 | if copy: |
| 1358 | H = self.__class__() |
| 1359 | H.graph.update(deepcopy(self.graph)) |
| 1360 | H.add_nodes_from((n, deepcopy(d)) for n, d in self.nodes.items()) |
| 1361 | H.add_edges_from((v, u, deepcopy(d)) for u, v, d in self.edges(data=True)) |
| 1362 | return H |
| 1363 | return nx.reverse_view(self) |