code: def spdiags(data, diags, m=None, n=None, format=None):
      """
      Return a sparse matrix from diagonals.
  
      Parameters
      ----------
      data : array_like
          Matrix diagonals stored row-wise
      diags : sequence of int or an int
          Diagonals to set:
  
          * k = 0  the main diagonal
          * k > 0  the kth upper diagonal
          * k < 0  the kth lower diagonal
      m, n : int, tuple, optional
          Shape of the result. If `n` is None and `m` is a given tuple,
          the shape is this tuple. If omitted, the matrix is square and
          its shape is len(data[0]).
      format : str, optional
          Format of the result. By default (format=None) an appropriate sparse
          matrix format is returned. This choice is subject to change.
  
      .. warning::
  
          This function returns a sparse matrix -- not a sparse array.
          You are encouraged to use ``diags_array`` to take advantage
          of the sparse array functionality.
  
      See Also
      --------
      diags_array : more convenient form of this function
      diags : matrix version of diags_array
      dia_matrix : the sparse DIAgonal format.
  
      Examples
      --------
      >>> import numpy as np
      >>> from scipy.sparse import spdiags
      >>> data = np.array([[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]])
      >>> diags = np.array([0, -1, 2])
      >>> spdiags(data, diags, 4, 4).toarray()
      array([[1, 0, 3, 0],
             [1, 2, 0, 4],
             [0, 2, 3, 0],
             [0, 0, 3, 4]])
  
      """
      if m is None and n is None:
          m = n = len(data[0])
      elif n is None:
          m, n = m
      return dia_matrix((data, diags), shape=(m, n)).asformat(format)
  
imports: import numbers
  import math
  import numpy
  from scipy._lib._util import check_random_state, rng_integers
  from ._sputils import upcast, get_index_dtype, isscalarlike
  from ._sparsetools import csr_hstack
  from ._bsr import bsr_matrix, bsr_array
  from ._coo import coo_matrix, coo_array
  from ._csc import csc_matrix, csc_array
  from ._csr import csr_matrix, csr_array
  from ._dia import dia_matrix, dia_array
  from ._base import issparse, sparray
label_desc: Use image node_id 1 for calling a global function with example usage: spdiags(data, diags, m, n, format) and returns: dia_matrix