code: def diagonal(x, offset=0, axis1=0, axis2=1):
      """Take diagonal
  
      Axes other than ``axis1`` and ``axis2`` are regarded as batch dimensions.
  
      Args:
          x (:class:`~chainer.Variable` or :ref:`ndarray`):
              A variable to be sliced.
          offset (int): Offset from the principal diagonal. An upper diagonal
              matrix can have nonzero diagonals with nonnegative offsets.
          axis1 (int): First axis (that has row indices) of matrix
          axis2 (int): Second axis (that has column indices) of matrix
  
      Returns:
          ~chainer.Variable: (Batched) diagonal vectors
  
      .. admonition:: Example
  
          >>> x = chainer.Variable(np.arange(9).reshape(3, 3).astype(np.float32))
          >>> x
          variable([[0., 1., 2.],
                    [3., 4., 5.],
                    [6., 7., 8.]])
          >>> chainer.functions.diagonal(x, offset=1)
          variable([1., 5.])
  
      """
      return Diagonal(offset, axis1, axis2).apply((x,))[0]
  
file_path: chainer/chainer/functions/array/diagonal.py
imports: import numpy
  from chainer import backend
  from chainer import function_node
  from chainer.utils import type_check
label_desc: Use image node_id 1 for calling a global function with example usage: diagonal(x, offset, axis1, axis2) and returns: Diagonal