Created
May 28, 2020 17:44
-
-
Save jamesharr/92bc1ffc61595d625fd5ab6860c755c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import networkx as nx | |
import community | |
G = nx.Graph() | |
G.add_node('node_a') | |
G.add_node('node_b') | |
G.add_node('node_c') | |
G.add_node('node_d') | |
G.add_edges_from([ | |
('node_a', 'node_b', {"weight":10}), | |
('node_a', 'node_c', {"weight":100}), | |
('node_a', 'node_d', {"weight":10}), | |
('node_b', 'node_c', {"weight":10}), | |
('node_b', 'node_d', {"weight":100}), | |
('node_c', 'node_d', {"weight":10}), | |
]) | |
p = community.best_partition(G, weight='weight') | |
print(p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: