code: def diagflat(v, k=0):
      """
      Create a two-dimensional array with the flattened input as a diagonal.
  
      Parameters
      ----------
      v : array_like
          Input data, which is flattened and set as the `k`-th
          diagonal of the output.
      k : int, optional
          Diagonal to set; 0, the default, corresponds to the "main" diagonal,
          a positive (negative) `k` giving the number of the diagonal above
          (below) the main.
  
      Returns
      -------
      out : ndarray
          The 2-D output array.
  
      See Also
      --------
      diag : MATLAB work-alike for 1-D and 2-D arrays.
      diagonal : Return specified diagonals.
      trace : Sum along diagonals.
  
      Examples
      --------
      >>> np.diagflat([[1,2], [3,4]])
      array([[1, 0, 0, 0],
             [0, 2, 0, 0],
             [0, 0, 3, 0],
             [0, 0, 0, 4]])
  
      >>> np.diagflat([1,2], 1)
      array([[0, 1, 0],
             [0, 0, 2],
             [0, 0, 0]])
  
      """
      try:
          wrap = v.__array_wrap__
      except AttributeError:
          wrap = None
      v = asarray(v).ravel()
      s = len(v)
      n = s + abs(k)
      res = zeros((n, n), v.dtype)
      if k >= 0:
          i = arange(0, n - k, dtype=intp)
          fi = i + k + i * n
      else:
          i = arange(0, n + k, dtype=intp)
          fi = i + (i - k) * n
      res.flat[fi] = v
      if not wrap:
          return res
      return wrap(res)
  
imports: import functools
  import operator
  from numpy.core.numeric import asanyarray, arange, zeros, greater_equal, multiply, ones, asarray, where, int8, int16, int32, int64, intp, empty, promote_types, diagonal, nonzero, indices
  from numpy.core.overrides import set_array_function_like_doc, set_module
  from numpy.core import overrides
  from numpy.core import iinfo
  from numpy.lib.stride_tricks import broadcast_to
label_desc: Use image node_id 8 for calling a global function with example usage: diagflat(v, k) and returns: wrap, res