def const_ext(x, n, axis=(-1)):
 if (n < 1):
  return x
 left_end = axis_slice(x, start=0, stop=1, axis=axis)
 ones_shape = ([1] * x.ndim)
 ones_shape[axis] = n
 ones = np.ones(ones_shape, dtype=x.dtype)
 left_ext = (ones * left_end)
 right_end = axis_slice(x, start=(-1), axis=axis)
 right_ext = (ones * right_end)
 ext = np.concatenate((left_ext, x, right_ext), axis=axis)
 return ext

def const_ext ( x , n , axis = ( - 1 ) ) : if ( n < 1 ) : return x left_end = axis_slice ( x , start = 0 , stop = 1 , axis = axis ) ones_shape = ( [ 1 ] * x . ndim ) ones_shape [ axis ] = n ones = np . ones ( ones_shape , dtype = x . dtype ) left_ext = ( ones * left_end ) right_end = axis_slice ( x , start = ( - 1 ) , axis = axis ) right_ext = ( ones * right_end ) ext = np . concatenate ( ( left_ext , x , right_ext ) , axis = axis ) return ext
constant extension at the boundaries of an array generate a new ndarray that is a constant extension of x along an axis .