I have a network with nodes and vertices and the following numbering scheme. I want to generate an adjacency matrix A for the nodes 0,1 as shown below. I tried to do using networkx. I present the current and expected outputs.
import networkx as nx
N=2
def pos():
x, y = 1, N + 3 - 1
for _ in range(N):
yield (x, y)
y -= (x + 2) // (N+1 )
x = (x + 2) % (N+1)
G = nx.Graph()
it_pos = pos()
for u in range(N):
G.add_node(u+1, pos=next(it_pos))
if u % (2 * N) < N:
for v in (u - 2 * N, u - N, u - N):
if G.has_node(v + 1):
G.add_edge(u + 2, v + 2)
elif u % (2 * N) == N:
G.add_edge(u + 1, u - N + 1)
elif u % (2 * N + 1) < 2 * N:
for v in (u - 1, u - N, u - N):
G.add_edge(u + 1, v + 1)
else:
for v in (u - 1, u - N - 1):
G.add_edge(u + 1, v + 1)
nx.draw(G, nx.get_node_attributes(G, 'pos'), with_labels=True, font_weight='bold')
Nodes=len(G.nodes)
A=nx.adjacency_matrix(G).todense()
The current output is
A=matrix([[0., 0.],
[0., 0.]])
The expected output is

