The code generates a 2D grid graph. However, there is problem with the adjacency matrix it generates. For instance, node 1 is not connected to 3 but in the matrix, it shows value 1. For node 2, it shows value 0 even though it is connected to node 3 and similarly for other nodes. The adjacency matrix and the 2D grid graph are attached here.
import numpy as np
import networkx as nx
G = nx.grid_2d_graph(3,3)
new_nodes = {e: n for n, e in enumerate(G.nodes, start=1)}
new_edges = [(new_nodes[e1], new_nodes[e2]) for e1, e2 in G.edges]
G = nx.Graph()
G.add_edges_from(new_edges)
nx.draw(G, with_labels=True)
A1 = nx.adjacency_matrix(G)
A=A1.toarray()
print([A])