grid_2d_graph

grid_2d_graph(m, n, periodic=False, create_using=None)[source]

Returns the two-dimensional grid graph.

The grid graph has each node connected to its four nearest neighbors.

Parameters
m, nint or iterable container of nodes

If an integer, nodes are from range(n). If a container, elements become the coordinate of the nodes.

periodicbool or iterable

If periodic is True, both dimensions are periodic. If False, none are periodic. If periodic is iterable, it should yield 2 bool values indicating whether the 1st and 2nd axes, respectively, are periodic.

create_usingNetworkX graph constructor, optional (default=nx.Graph)

Graph type to create. If graph instance, then cleared before populated.

Returns
NetworkX graph

The (possibly periodic) grid graph of the specified dimensions.