5.2.9. networkx.generators.classic.grid_2d_graph

networkx.generators.classic.grid_2d_graph(m, n, periodic=False, create_using=None)[source]

Return the 2d grid graph of mxn nodes

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

Parameters:

m, n : int or iterable container of nodes (default = 0)

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

periodic : bool (default = False)

If True will connect boundary nodes in periodic fashion.

create_using : Graph, optional (default Graph())

If provided this graph is cleared of nodes and edges and filled with the new graph. Usually used to set the type of the graph.