Try the following code
n=3
adjacency_matrix =[ [2, 3, 0] , [0, 0, 1] , [1, 5, 0] ]
li_r = []
li_c = []
for i in range(n):
for j in range(n):
if adjacency_matrix[i][j]!=0:
li_r.append(i)
li_c.append(j)
print(li_r)
print(li_c)
You may also use the more concise, but less efficient
n=3
adjacency_matrix =[ [2, 3, 0] , [0, 0, 1] , [1, 5, 0] ]
li_r = [r for r in range(n) for c in range(n) if adjacency_matrix[r][c] != 0]
li_c = [c for r in range(n) for c in range(n) if adjacency_matrix[r][c] != 0]
print(li_r)
print(li_c)