code: def const_ext(x, n, axis=-1):
      """
      Constant extension at the boundaries of an array
  
      Generate a new ndarray that is a constant extension of `x` along an axis.
  
      The extension repeats the values at the first and last element of
      the axis.
  
      Parameters
      ----------
      x : ndarray
          The array to be extended.
      n : int
          The number of elements by which to extend `x` at each end of the axis.
      axis : int, optional
          The axis along which to extend `x`. Default is -1.
  
      Examples
      --------
      >>> from scipy.signal._arraytools import const_ext
      >>> a = np.array([[1, 2, 3, 4, 5], [0, 1, 4, 9, 16]])
      >>> const_ext(a, 2)
      array([[ 1,  1,  1,  2,  3,  4,  5,  5,  5],
             [ 0,  0,  0,  1,  4,  9, 16, 16, 16]])
  
      Constant extension continues with the same values as the endpoints of the
      array:
  
      >>> t = np.linspace(0, 1.5, 100)
      >>> a = 0.9 * np.sin(2 * np.pi * t**2)
      >>> b = const_ext(a, 40)
      >>> import matplotlib.pyplot as plt
      >>> plt.plot(arange(-40, 140), b, 'b', lw=1, label='constant extension')
      >>> plt.plot(arange(100), a, 'r', lw=2, label='original')
      >>> plt.legend(loc='best')
      >>> plt.show()
      """
      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
  
imports: import numpy
label_desc: Use image node_id 5 for calling a global function with example usage: const_ext(x, n, axis) and returns: ext, x