import numpy as np
E = np.array([[1, 2, 4],
[2, 5, 4],
[2, 3, 5],
[3, 6, 5],
[4, 5, 7],
[5, 8, 7],
[5, 6, 8],
[6, 9, 8]])
Nn = np.max(E)
print("maximum node number: \n", Nn)
n_row, n_column = E.shape
print("\n", n_row, n_column)
n_list = [[] for x in range(Nn)]
print("\n initialize n vector\n", n_list)
k = 1
while k <= Nn:
print(k)
for i in range(n_row):
for j in range(n_column):
if E[i, j] == k:
n_list[i].append(E[i, :])
k = k + 1
print("\n n vector\n", n_list)
I'm new to programming. I have a matrix that shows how 9 nodes are connected. If nodes appear in the same row then they are connected. I created a list of lists (9 rows) so that, for each node from 1 to 9, I can add the entire row of matrix to the specific row of list. For example, for node 1, I want to add the entire first row of matrix to the first row of list. And for the node 2, I want to add row 1, 2, 3 of the matrix to the second row of list. How do I fix this code to do that?