hypercube_graph#
- hypercube_graph(n)[source]#
Returns the n-dimensional hypercube graph.
The n-dimensional hypercube graph [1] has
2**n
nodes, each represented as a binary integer in the form of a tuple of 0’s and 1’s. Edges exist between nodes that differ in exactly one bit.- Parameters:
- nint
Dimension of the hypercube, must be a positive integer.
- Returns:
- networkx.Graph
The n-dimensional hypercube graph as an undirected graph.
References
Examples
>>> G = nx.hypercube_graph(3) >>> list(G.neighbors((0, 0, 0))) [(1, 0, 0), (0, 1, 0), (0, 0, 1)]