April 2019
Beginner
190 pages
4h 54m
English
In order to visualize communities, it will be necessary to define some helper functions. First, it is convenient to set a property on nodes and edges to specify their community. The following helper functions do exactly this:
def set_node_community(G, communities): '''Add community to node attributes''' for c, v_c in enumerate(communities): for v in v_c: # Add 1 to save 0 for external edges G.nodes[v]['community'] = c + 1 def set_edge_community(G): '''Find internal edges and add their community to their attributes''' for v, w, in G.edges: if G.nodes[v]['community'] == G.nodes[w]['community']: # Internal edge, mark with community G.edges[v, w]['community'] = G.nodes[v]['community'] else: # External edge, mark as 0 G.edges[v, w]['community'] ...
Read now
Unlock full access