def cartesian_product(G, H):
 if (not (G.is_directed() == H.is_directed())):
  raise nx.NetworkXError('G and H must be both directed or', 'both undirected')
 GH = _init_product_graph(G, H)
 GH.add_nodes_from(_node_product(G, H))
 GH.add_edges_from(_edges_cross_nodes(G, H))
 GH.add_edges_from(_nodes_cross_edges(G, H))
 GH.name = (((('Cartesian product(' + G.name) + ',') + H.name) + ')')
 return GH

def cartesian_product ( G , H ) : if ( not ( G . is_directed ( ) == H . is_directed ( ) ) ) : raise nx . NetworkXError ( 'G and H must be both directed or' , 'both undirected' ) GH = _init_product_graph ( G , H ) GH . add_nodes_from ( _node_product ( G , H ) ) GH . add_edges_from ( _edges_cross_nodes ( G , H ) ) GH . add_edges_from ( _nodes_cross_edges ( G , H ) ) GH . name = ( ( ( ( 'Cartesian product(' + G . name ) + ',' ) + H . name ) + ')' ) return GH
numpy version of itertools .