DM554/DM545 – Linear and Integer Programming
Networks and Graphs in Python
In [1]:
 
import networkx as nx
import numpy as np
A = np.reshape(np.random.random_integers(0,1,size=100),(10,10))
A
    Out[1]: 
In [2]:
 
np.array_equal(A.T,A)
    Out[2]: 
In [3]:
 
B = A+A.T
C = np.array(B==1,dtype=int)
np.array_equal(C.T,C)
    Out[3]: 
In [4]:
 
G = nx.Graph(C)
D = nx.DiGraph(A)
In [5]:
 
%matplotlib inline
In [6]:
 
nx.draw(G)
In [7]:
 
nx.draw(D)
 |