#NEWLINE# def cartesian( nodes , order = 'C' ) : #NEWLINE# #INDENT# "Cartesian product of a list of arrays\n\n    Parameters:\n    -----------\n    nodes: (list of 1d-arrays)\n    order: ('C' or 'F') order in which the product is enumerated\n\n    Returns:\n    --------\n    out: (2d-array) each line corresponds to one point of the product space\n    " #NEWLINE# nodes = [ numpy . array ( e ) for e in nodes ] #NEWLINE# shapes = [ e . shape [ 0 ] for e in nodes ] #NEWLINE# dtype = nodes [ 0 ] . dtype #NEWLINE# n = len ( nodes ) #NEWLINE# l = numpy . prod ( shapes ) #NEWLINE# out = numpy . zeros ( ( l , n ) , dtype = dtype ) #NEWLINE# if ( order == 'C' ) : #NEWLINE# #INDENT# repetitions = numpy . cumprod ( ( [ 1 ] + shapes [ : ( - 1 ) ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# shapes . reverse ( ) #NEWLINE# sh = ( [ 1 ] + shapes [ : ( - 1 ) ] ) #NEWLINE# repetitions = numpy . cumprod ( sh ) #NEWLINE# repetitions = repetitions . tolist ( ) #NEWLINE# repetitions . reverse ( ) #NEWLINE# #UNINDENT# for i in range ( n ) : #NEWLINE# #INDENT# _repeat_1d ( nodes [ i ] , repetitions [ i ] , out [ : , i ] ) #NEWLINE# #UNINDENT# return out