def _zero_pad(array, amount, axes=(1, 2)):
 if (amount == 0):
  return array
 new_shape = []
 slices = []
 for (i, s) in enumerate(array.shape):
  if (i in axes):
   new_shape.append((s + (2 * amount)))
   slices.append(slice(amount, (- amount)))
  else:
   new_shape.append(s)
   slices.append(slice(None))
 new_shape = tuple(new_shape)
 slices = tuple(slices)
 new_array = numpy.zeros(new_shape, dtype=array.dtype)
 new_array[slices] = array
 return new_array

def _zero_pad ( array , amount , axes = ( 1 , 2 ) ) : if ( amount == 0 ) : return array new_shape = [ ] slices = [ ] for ( i , s ) in enumerate ( array . shape ) : if ( i in axes ) : new_shape . append ( ( s + ( 2 * amount ) ) ) slices . append ( slice ( amount , ( - amount ) ) ) else : new_shape . append ( s ) slices . append ( slice ( None ) ) new_shape = tuple ( new_shape ) slices = tuple ( slices ) new_array = numpy . zeros ( new_shape , dtype = array . dtype ) new_array [ slices ] = array return new_array
returns a copy of <array> with zero-filled padding around the margins .