diff options
author | Navya Agarwal <82928853+navyagarwal@users.noreply.github.com> | 2023-04-11 20:54:19 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-11 11:24:19 -0400 |
commit | 58f7b352b4ee99b7f185cc3a54caa6941c209fe3 (patch) | |
tree | d1465e7aec014d75db9d757fcf100929a6cc292d | |
parent | 4859ed12f719f9c9581bbb7e0e9c3d2c4843ee14 (diff) | |
download | networkx-58f7b352b4ee99b7f185cc3a54caa6941c209fe3.tar.gz |
Add examples to bipartite centrality.py (#6613)
* Add examples to bipartite centrality.py
* Import bipartite module
* Use lazy loading for bipartite
* Minor Edit
-rw-r--r-- | networkx/algorithms/bipartite/centrality.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/networkx/algorithms/bipartite/centrality.py b/networkx/algorithms/bipartite/centrality.py index 3eab8342..52437c64 100644 --- a/networkx/algorithms/bipartite/centrality.py +++ b/networkx/algorithms/bipartite/centrality.py @@ -22,6 +22,13 @@ def degree_centrality(G, nodes): centrality : dictionary Dictionary keyed by node with bipartite degree centrality as the value. + Examples + -------- + >>> G = nx.wheel_graph(5) + >>> top_nodes = {0, 1, 2} + >>> nx.bipartite.degree_centrality(G, nodes=top_nodes) + {0: 2.0, 1: 1.5, 2: 1.5, 3: 1.0, 4: 1.0} + See Also -------- betweenness_centrality @@ -120,6 +127,13 @@ def betweenness_centrality(G, nodes): Dictionary keyed by node with bipartite betweenness centrality as the value. + Examples + -------- + >>> G = nx.cycle_graph(4) + >>> top_nodes = {1, 2} + >>> nx.bipartite.betweenness_centrality(G, nodes=top_nodes) + {0: 0.25, 1: 0.25, 2: 0.25, 3: 0.25} + See Also -------- degree_centrality @@ -190,6 +204,13 @@ def closeness_centrality(G, nodes, normalized=True): Dictionary keyed by node with bipartite closeness centrality as the value. + Examples + -------- + >>> G = nx.wheel_graph(5) + >>> top_nodes = {0, 1, 2} + >>> nx.bipartite.closeness_centrality(G, nodes=top_nodes) + {0: 1.5, 1: 1.2, 2: 1.2, 3: 1.0, 4: 1.0} + See Also -------- betweenness_centrality |