### diff env/lib/python3.9/site-packages/networkx/algorithms/operators/unary.py @ 0:4f3585e2f14bdraftdefaulttip

author shellac Mon, 22 Mar 2021 18:12:50 +0000
line wrap: on
line diff
```--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/env/lib/python3.9/site-packages/networkx/algorithms/operators/unary.py	Mon Mar 22 18:12:50 2021 +0000
@@ -0,0 +1,54 @@
+"""Unary operations on graphs"""
+import networkx as nx
+
+__all__ = ["complement", "reverse"]
+
+
+def complement(G):
+    """Returns the graph complement of G.
+
+    Parameters
+    ----------
+    G : graph
+       A NetworkX graph
+
+    Returns
+    -------
+    GC : A new graph.
+
+    Notes
+    ------
+    Note that complement() does not create self-loops and also
+    does not produce parallel edges for MultiGraphs.
+
+    Graph, node, and edge data are not propagated to the new graph.
+    """
+    R = G.__class__()
+        ((n, n2) for n, nbrs in G.adjacency() for n2 in G if n2 not in nbrs if n != n2)
+    )
+    return R
+
+
+def reverse(G, copy=True):
+    """Returns the reverse directed graph of G.
+
+    Parameters
+    ----------
+    G : directed graph
+        A NetworkX directed graph
+    copy : bool
+        If True, then a new graph is returned. If False, then the graph is
+        reversed in place.
+
+    Returns
+    -------
+    H : directed graph
+        The reversed G.
+
+    """
+    if not G.is_directed():
+        raise nx.NetworkXError("Cannot reverse an undirected graph.")
+    else:
+        return G.reverse(copy=copy)```