#NEWLINE# def _zero_pad( array , amount , axes = ( 1 , 2 ) ) : #NEWLINE# #INDENT# "\n    Returns a copy of <array> with zero-filled padding around the margins.\n\n    The new array has the same dimensions as the input array, except for\n    the dimensions given by <axes>, which are increased by 2*<amount>.\n\n    Parameters\n    ----------\n    array: numpy.ndarray\n      The array to zero-pad.\n\n    amount: int\n      The number of zeros to append to the beginning and end of each dimension\n      in <axes>. (That axis will grow by 2*<amount>).\n\n    axes: tuple\n      The dimensions to pad. These are indices, not axis names like the 0, 1\n      in ('b', 0, 1, 'c').\n    " #NEWLINE# if ( amount == 0 ) : #NEWLINE# #INDENT# return array #NEWLINE# #UNINDENT# new_shape = [ ] #NEWLINE# slices = [ ] #NEWLINE# for ( i , s ) in enumerate ( new_shape . shape ) : #NEWLINE# #INDENT# if ( i in axes ) : #NEWLINE# #INDENT# new_shape . append ( ( s + ( 2 * amount ) ) ) #NEWLINE# slices . append ( slice ( amount , ( - amount ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# new_shape . append ( s ) #NEWLINE# slices . append ( slice ( None ) ) #NEWLINE# #UNINDENT# #UNINDENT# new_shape = tuple ( new_shape ) #NEWLINE# slices = tuple ( slices ) #NEWLINE# new_array = numpy . zeros ( new_shape , dtype = array . dtype ) #NEWLINE# new_array [ slices ] = array #NEWLINE# return new_array