See here: http://networkx.lanl.gov/reference/algorithms.centrality.html for a list of centrality algorithms implemented in networkx
Created
October 15, 2014 07:04
-
-
Save luca/0a76eb5cf65a562cee0e to your computer and use it in GitHub Desktop.
Calculating centrality with networkx
This file contains 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
import networkx as nx | |
# this is a directed graph | |
dg=nx.DiGraph() | |
# For all the nodes ... | |
# this adds a node to the graph | |
# - node could be any hashable object | |
# - attr_dict is an (optional) dictionary with attributes for the node | |
dg.add_node(node, attr_dict) | |
# For all edges ... | |
# this adds an edge from source to target | |
# - source, target could be any hashable object | |
# - attr_dict is an (optional) dictionary with attributes for the edge | |
dg.add_edge(source, target, attr_dict) | |
# This returns a dictionary { node => centrality value } | |
centrality_dict = nx.betweenness_centrality(dg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment