eccentricity#

eccentricity(G, v=None, sp=None)[source]#

Returns the eccentricity of nodes in G.

The eccentricity of a node v is the maximum distance from v to all other nodes in G.

Parameters:
GNetworkX graph

A graph

vnode, optional

Return value of specified node

spdict of dicts, optional

All pairs shortest path lengths as a dictionary of dictionaries

Returns:
eccdictionary

A dictionary of eccentricity values keyed by node.

Examples

>>> G = nx.Graph([(1, 2), (1, 3), (1, 4), (3, 4), (3, 5), (4, 5)])
>>> dict(nx.eccentricity(G))
{1: 2, 2: 3, 3: 2, 4: 2, 5: 3}
>>> dict(nx.eccentricity(G, v=[1, 5]))  # This returns the eccentrity of node 1 & 5
{1: 2, 5: 3}