def grid_graph(dim, periodic=False):
 dlabel = ('%s' % str(dim))
 if (not dim):
  G = empty_graph(0)
  G.name = ('grid_graph(%s)' % dlabel)
  return G
 if periodic:
  func = cycle_graph
 else:
  func = path_graph
 G = func(dim[0])
 for current_dim in dim[1:]:
  Gold = G.copy()
  Gnew = func(current_dim)
  G = nx.cartesian_product(Gnew, Gold)
 H = nx.relabel_nodes(G, flatten)
 H.name = ('grid_graph(%s)' % dlabel)
 return H

def grid_graph ( dim , periodic = False ) : dlabel = ( '%s' % str ( dim ) ) if ( not dim ) : G = empty_graph ( 0 ) G . name = ( 'grid_graph(%s)' % dlabel ) return G if periodic : func = cycle_graph else : func = path_graph G = func ( dim [ 0 ] ) for current_dim in dim [ 1 : ] : Gold = G . copy ( ) Gnew = func ( current_dim ) G = nx . cartesian_product ( Gnew , Gold ) H = nx . relabel_nodes ( G , flatten ) H . name = ( 'grid_graph(%s)' % dlabel ) return H
return the n-dimensional grid graph .