code: def add_constant(data, prepend=True, has_constant="skip"):
      """
      Add a column of ones to an array.
  
      Parameters
      ----------
      data : array_like
          A column-ordered design matrix.
      prepend : bool
          If true, the constant is in the first column.  Else the constant is
          appended (last column).
      has_constant : str {'raise', 'add', 'skip'}
          Behavior if ``data`` already has a constant. The default will return
          data without adding another constant. If 'raise', will raise an
          error if any column has a constant value. Using 'add' will add a
          column of 1s if a constant column is present.
  
      Returns
      -------
      array_like
          The original values with a constant (column of ones) as the first or
          last column. Returned value type depends on input type.
  
      Notes
      -----
      When the input is a pandas Series or DataFrame, the added column's name
      is 'const'.
      """
      if _is_using_pandas(data, None):
          from statsmodels.tsa.tsatools import add_trend
  
          return add_trend(
              data,
              trend="c",
              prepend=prepend,
              has_constant=has_constant,
          )
  
      # Special case for NumPy
      x = np.asarray(data)
      ndim = x.ndim
      if ndim == 1:
          x = x[:, None]
      elif x.ndim > 2:
          raise ValueError("Only implemented for 2-dimensional arrays")
  
      is_nonzero_const = np.ptp(x, axis=0) == 0
      is_nonzero_const &= np.all(x != 0.0, axis=0)
      if is_nonzero_const.any():
          if has_constant == "skip":
              return x
          elif has_constant == "raise":
              if ndim == 1:
                  raise ValueError("data is constant.")
              else:
                  columns = np.arange(x.shape[1])
                  cols = ",".join(
                      [str(c) for c in columns[is_nonzero_const]]
                  )
                  raise ValueError(f"Column(s) {cols} are constant.")
  
      x = [np.ones(x.shape[0]), x]
      x = x if prepend else x[::-1]
      return np.column_stack(x)
  
imports: import numpy
  import pandas
  import scipy.linalg
  from statsmodels.tools.data import _is_using_pandas
  from statsmodels.tools.validation import array_like
label_desc: Use image node_id 5 for calling a global function with example usage: add_constant(data, prepend, has_constant) and returns: np, add_trend, x