In [21]:
%matplotlib inline

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


t1 = np.array([[1,3,1,1],[3,1,1,1],[1,1,1,1],[1,1,1,1]])
g = nx.to_networkx_graph(t1)

In [23]:
nx.draw(g)



In [24]:
t1


Out[24]:
array([[1, 3, 1, 1],
       [3, 1, 1, 1],
       [1, 1, 1, 1],
       [1, 1, 1, 1]])

In [25]:
g.add_node(4)
g.add_edge(1,4)

In [26]:
nx.draw(g)



In [27]:
m1 = nx.to_numpy_matrix(g)
print m1


[[ 1.  3.  1.  1.  0.]
 [ 3.  1.  1.  1.  1.]
 [ 1.  1.  1.  1.  0.]
 [ 1.  1.  1.  1.  0.]
 [ 0.  1.  0.  0.  0.]]

In [28]:
g.remove_node(3)

In [29]:
nx.draw(g)



In [30]:
nx.to_numpy_matrix(g)


Out[30]:
matrix([[ 1.,  3.,  1.,  0.],
        [ 3.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  0.],
        [ 0.,  1.,  0.,  0.]])

In [31]:
m2 = nx.to_numpy_matrix(g)

In [32]:
print m2


[[ 1.  3.  1.  0.]
 [ 3.  1.  1.  1.]
 [ 1.  1.  1.  0.]
 [ 0.  1.  0.  0.]]

In [34]:
g.


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-34-0b3be76d148a> in <module>()
----> 1 g.node(4, {active: 1})

NameError: name 'active' is not defined

In [35]:



---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-35-5aa6d47dbeb0> in <module>()
----> 1 v4 = g.node(4)

TypeError: 'dict' object is not callable

In [ ]: