code: def diagonal(a, offset=0):
      r"""
      Returns the specified diagonals of a matrix (or a stack of matrices) `a`.
  
      Notes
      -----
      `diagonal` is an alias for `diagonal`. It is a standard API in
      https://data-apis.org/array-api/latest/extensions/linear_algebra_functions.html#linalg-diagonal-x-offset-0
      instead of an official NumPy operator.
  
      Parameters
      ----------
      a : ndarray
          The array to apply diag method.
      offset : int
          Extracts or constructs kth diagonal given input array.
          Offset specifying the off-diagonal relative to the main diagonal.
  
          offset = 0 : the main diagonal.
          offset > 0 : off-diagonal above the main diagonal.
          offset < 0 : off-diagonal below the main diagonal.
  
          Default: 0.
  
      Returns
      ----------
      out : ndarray
          An array containing the diagonals and whose shape is determined by removing the last two dimensions and
          appending a dimension equal to the size of the resulting diagonals.
          The returned array must have the same data type as a.
  
      Examples
      --------
      >>> x = np.arange(9).reshape((3,3))
      >>> x
      array([[0., 1., 2.],
             [3., 4., 5.],
             [6., 7., 8.]])
      >>> np.linalg.diagonal(x)
      array([0., 4., 8.])
      >>> np.linalg.diagonal(x, offset=1)
      array([1., 5.])
      >>> np.linalg.diagonal(x, offset=-1)
      array([3., 7.])
      """
      return _mx_nd_np.diag(a, k=offset)
  
imports: from functools import reduce
  from ..ndarray import numpy
  from ..util import wrap_data_api_linalg_func
  from .fallback_linalg import *
  from .None import fallback_linalg
label_desc: Use image node_id 5 for calling a global function with example usage: diagonal(a, offset) and returns: _mx_nd_np