Given an edge list, I need to convert the list to an adjacency matrix in Python. I am very, very close, but I cannot figure out what I am doing incorrectly. Where is my thinking incorrect?
E= [[0, 0], [0, 1], [1, 0], [1, 1]]
nmax = max(E)
nmax2 =max(nmax)
m = []
for i in range(nmax2+1):
row = []
for j in range(nmax2+1):
if [i,j]== E[i]:
row.append(1)
else:
row.append(0)
m.append(row)
print(m)
I would expect the result to be: 1 1 1 1
But my code produces: 1 0 0 0
E[i]goes maximum up toE[1]becauseigoes only from 0 to 1. So you never reach [1, 0] and [1, 1]