networkx 2.8.2 Pypi GitHub Homepage
Other Docs
ParametersReturnsBackRef
grid_graph(dim, periodic=False)

The dimension n is the length of the list :None:None:`dim` and the size in each dimension is the value of the corresponding list element.

Parameters

dim : list or tuple of numbers or iterables of nodes

'dim' is a tuple or list with, for each dimension, either a number that is the size of that dimension or an iterable of nodes for that dimension. The dimension of the grid_graph is the length of :None:None:`dim`.

periodic : bool or iterable

If periodic is True, all dimensions are periodic. If False all dimensions are not periodic. If periodic is iterable, it should yield :None:None:`dim` bool values each of which indicates whether the corresponding axis is periodic.

Returns

NetworkX graph

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

Returns the n-dimensional grid graph.

Examples

To produce a 2 by 3 by 4 grid graph, a graph on 24 nodes:

>>> from networkx import grid_graph
... G = grid_graph(dim=(2, 3, 4))
... len(G) 24
>>> G = grid_graph(dim=(range(7, 9), range(3, 6)))
... len(G) 6
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.algorithms.shortest_paths.astar.astar_path networkx.generators.lattice.grid_graph

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/generators/lattice.py#89
type: <class 'function'>
Commit: