In [3]:
%pylab inline
%matplotlib inline


Populating the interactive namespace from numpy and matplotlib

In [2]:
import numpy as np
import networkx as nx

In [5]:


In [6]:
G = nx.Graph()
G.add_path([0,1,2,3])
nx.draw(G)



In [8]:
G.add_path([10,11,12],weight=7)
nx.draw(G)



In [10]:
G = nx.Graph()
G.add_star([0,1,2,3])
nx.draw(G)


Iterating through Nodes


In [13]:
G = nx.Graph()
G.add_path([0,1,2])
[n for n in G.nodes_iter()]


Out[13]:
[0, 1, 2]

In [15]:
#Dictionary of the nodes
[d for n,d in G.nodes_iter(data=True)]


Out[15]:
[{}, {}, {}]

Neighbors


In [6]:
ex = nx.MultiDiGraph()
ex.add_nodes_from(['a','b','c','d','e','f','g','h','i','j','k','l','d1','d2','d3','d4','v1','v2','v3','v4'])
ex.add_edges_from([('a','c'),('b','c'),('b','d'),('b','d1'),('d','f'),('c','e'),('d','e'),('e','g')])
ex.add_edges_from([('e', 'd2'), ('f', 'd2'), ('f', 'h'), ('h', 'j'), ('h', 'k'), ('k', 'v3'), ('j', 'v3')])
ex.add_edges_from([('d4','l'), ('l', 'v4'), ('i', 'l')])

ex.add_edges_from([('d1','d'), ('d1', 'v1'), ('d2', 'i'), ('d2', 'd3'), ('d3', 'd4'), ('d4', 'l')])
nx.draw(ex)



In [9]:
ex.neighbors('e')


Out[9]:
['d2', 'g']

In [ ]: