In [3]:
import networkx as nx
%matplotlib inline
import matplotlib
matplotlib.rcParams['figure.figsize'] = (10.0, 8.0)
import numpy as np
In [4]:
AG=nx.read_gpickle("../data/airport/smaller_airportnet.pickle")
E1.1 Explore the graph AG using the methods:
etc.
Draw the graph using nx.draw
In [5]:
AG.nodes()
Out[5]:
In [6]:
AG.edges()
Out[6]:
In [7]:
nx.draw(AG)
E1.2 Find out the average distance between all pairs of airports in AG
In [8]:
np.average([nx.shortest_path_length(AG, source=u, target=v) for u in AG.nodes() for v in AG.nodes() if u!=v])
Out[8]:
E1.3 Find out which airport in AG has the highest number of neighbours.
In [9]:
maxnei=0
node_w_max_nei=None
for n in AG.nodes():
numnei=len(AG[n])
if numnei>maxnei:
maxnei=numnei
node_w_max_nei=n
print(node_w_max_nei)
E1.4 Now remove that node from AG, and redo E1.2.
In [10]:
AG.remove_node('LAX')
In [11]:
np.average([nx.shortest_path_length(AG, source=u, target=v) for u in AG.nodes() for v in AG.nodes() if u!=v])
Out[11]:
In [ ]: