###################################### # Copyright 2007 Martin T. Sandsmark # # This software is distributed under # # the GNU General Public License v3 # ###################################### # List to be processed list = [(1,1),(1,4),(2,1),(2,3),(3,1),(3,2),(3,4),(4,2)] #n, size of sides in matrix size = 4 # Do we output for LaTeX? TEX = True M = [] #size = len(M[0]) for i in range(size): M.append([0,0,0,0]) for tuppel in list: M[tuppel[0] - 1][tuppel[1] - 1] = 1 # The old Way (tm) #M.append([0, 1, 0, 0]) #M.append([1, 0, 1, 0]) #M.append([0, 0, 0, 1]) #M.append([1, 0, 0, 0]) def printmatrix(matrix): if TEX: print "\\left[ \\begin{array}{c c c c}" for i in range(len(matrix[0])): ut = '' for t in range(len(matrix[i])-1): ut = ut + str(matrix[i][t]) + "&" print ut + str(matrix[i][len(matrix[i])-1]) + "\\\\" print " \\end{array} \\right]" else: print matrix for k in range(size): for i in range(size): for j in range(size): M[i][j] = M[i][j] | (M[i][k] & M[k][j]) printmatrix(M)