In [1]:
import networkx as nx

348.edges is from the facebook SNAP data (https://snap.stanford.edu/data/egonets-Facebook.html)


In [2]:
G=nx.read_edgelist("348.edges")

If the graph isn't connected then we cannot get the diameter


In [3]:
print(nx.is_connected(G))


True

Some information about the graph:


In [4]:
G.number_of_nodes()


Out[4]:
224

In [5]:
G.number_of_edges()


Out[5]:
3192

In [6]:
G.number_of_selfloops()


Out[6]:
0

The diameter of the Graph:


In [7]:
nx.diameter(G)


Out[7]:
9

We will try to get the Vertex Degree, that is, the number of edges for each vertex


In [8]:
VertexDegree = {}

In [9]:
for i in G.nodes_iter():
    VertexDegree.update({i:len(G.neighbors(i))})

The node with the highest Degree is:


In [10]:
max(VertexDegree, key=VertexDegree.get)


Out[10]:
u'376'

In [12]:
VertexDegree.get('376')


Out[12]:
99

Let's look at the leaf nodes or those with only 1 connection


In [11]:
for node, deg in VertexDegree.iteritems():
    if deg == 1:
        print node


379
443
377
401
468

In [ ]: