#To find adjacency matrix of the graph in problem 4
print 'The adjacency matrix is'
A = matrix([[0,1,1,1],[1,0,1,1],[1,1,0,1],[1,1,1,0]])
print A
print 'To find the no. of 2 step paths from a node to another we square the adjacency matrix'
print 'The square of adjacency matrix is '
b = A**2
print A**2
def no_of_2step_paths(i,j):
    return b[i-1][j-1]
print 'For example the no of 2-step paths from node-1 to node-3 is ',
print no_of_2step_paths(1,3)

Strang-2.5-17-U (last edited 2010-12-18 11:43:14 by ArnabBasu)