# numpy 2.5.4 (BSD-3-Clause), harvested by tools/harvest_corpus.py
=== input

    Return the sum along diagonals of the array.

    If `a` is 2-D, the sum along its diagonal with the given offset
    is returned, i.e., the sum of elements ``a[i,i+offset]`` for all i.

    If `a` has more than two dimensions, then the axes specified by axis1 and
    axis2 are used to determine the 2-D sub-arrays whose traces are returned.
    The shape of the resulting array is the same as that of `a` with `axis1`
    and `axis2` removed.

    Parameters
    ----------
    a : array_like
        Input array, from which the diagonals are taken.
    offset : int, optional
        Offset of the diagonal from the main diagonal. Can be both positive
        and negative. Defaults to 0.
    axis1, axis2 : int, optional
        Axes to be used as the first and second axis of the 2-D sub-arrays
        from which the diagonals should be taken. Defaults are the first two
        axes of `a`.
    dtype : dtype, optional
        Determines the data-type of the returned array and of the accumulator
        where the elements are summed. If dtype has the value None and `a` is
        of integer type of precision less than the default integer
        precision, then the default integer precision is used. Otherwise,
        the precision is the same as that of `a`.
    out : ndarray, optional
        Array into which the output is placed. Its type is preserved and
        it must be of the right shape to hold the output.

    Returns
    -------
    sum_along_diagonals : ndarray
        If `a` is 2-D, the sum along the diagonal is returned.  If `a` has
        larger dimensions, then an array of sums along diagonals is returned.

    See Also
    --------
    diag, diagonal, diagflat

    Examples
    --------
    >>> import numpy as np
    >>> np.trace(np.eye(3))
    3.0
    >>> a = np.arange(8).reshape((2,2,2))
    >>> np.trace(a)
    array([6, 8])

    >>> a = np.arange(24).reshape((2,2,2,3))
    >>> np.trace(a).shape
    (2, 3)

    
=== parse numpydoc
short_description: 'Return the sum along diagonals of the array.'
long_description: |
  If `a` is 2-D, the sum along its diagonal with the given offset
  is returned, i.e., the sum of elements ``a[i,i+offset]`` for all i.
  
  If `a` has more than two dimensions, then the axes specified by axis1 and
  axis2 are used to determine the 2-D sub-arrays whose traces are returned.
  The shape of the resulting array is the same as that of `a` with `axis1`
  and `axis2` removed.
blank_after_short_description: True
blank_after_long_description: True
style: numpydoc
- DocstringParam
  description: 'Input array, from which the diagonals are taken.'
  kind: param
  key: 'param'
  arg_name: 'a'
  type_name: 'array_like'
  is_optional: False
- DocstringParam
  description: |
    Offset of the diagonal from the main diagonal. Can be both positive
    and negative. Defaults to 0.
  kind: param
  key: 'param'
  arg_name: 'offset'
  type_name: 'int'
  is_optional: True
  default: '0'
  raw_type_name: 'int, optional'
- DocstringParam
  description: |
    Axes to be used as the first and second axis of the 2-D sub-arrays
    from which the diagonals should be taken. Defaults are the first two
    axes of `a`.
  kind: param
  key: 'param'
  arg_name: 'axis1'
  type_name: 'int'
  is_optional: True
  raw_type_name: 'int, optional'
- DocstringParam
  description: |
    Axes to be used as the first and second axis of the 2-D sub-arrays
    from which the diagonals should be taken. Defaults are the first two
    axes of `a`.
  kind: param
  key: 'param'
  arg_name: 'axis2'
  type_name: 'int'
  is_optional: True
  raw_type_name: 'int, optional'
- DocstringParam
  description: |
    Determines the data-type of the returned array and of the accumulator
    where the elements are summed. If dtype has the value None and `a` is
    of integer type of precision less than the default integer
    precision, then the default integer precision is used. Otherwise,
    the precision is the same as that of `a`.
  kind: param
  key: 'param'
  arg_name: 'dtype'
  type_name: 'dtype'
  is_optional: True
  raw_type_name: 'dtype, optional'
- DocstringParam
  description: |
    Array into which the output is placed. Its type is preserved and
    it must be of the right shape to hold the output.
  kind: param
  key: 'param'
  arg_name: 'out'
  type_name: 'ndarray'
  is_optional: True
  raw_type_name: 'ndarray, optional'
- DocstringReturns
  description: |
    If `a` is 2-D, the sum along the diagonal is returned.  If `a` has
    larger dimensions, then an array of sums along diagonals is returned.
  kind: returns
  key: 'returns'
  type_name: 'ndarray'
  is_generator: False
  return_name: 'sum_along_diagonals'
- DocstringMeta
  description: 'diag, diagonal, diagflat'
  kind: text
  key: 'see_also'
  title: 'See Also'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> import numpy as np'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: |
    >>> np.trace(np.eye(3))
    3.0
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> a = np.arange(8).reshape((2,2,2))'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: |
    >>> np.trace(a)
    array([6, 8])
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: '>>> a = np.arange(24).reshape((2,2,2,3))'
- DocstringExample
  kind: examples
  key: 'examples'
  snippet: |
    >>> np.trace(a).shape
    (2, 3)
=== detect
numpydoc
=== compose numpydoc
Return the sum along diagonals of the array.

If `a` is 2-D, the sum along its diagonal with the given offset
is returned, i.e., the sum of elements ``a[i,i+offset]`` for all i.

If `a` has more than two dimensions, then the axes specified by axis1 and
axis2 are used to determine the 2-D sub-arrays whose traces are returned.
The shape of the resulting array is the same as that of `a` with `axis1`
and `axis2` removed.

Parameters
----------
a : array_like
    Input array, from which the diagonals are taken.
offset : int, optional
    Offset of the diagonal from the main diagonal. Can be both positive
    and negative. Defaults to 0.
axis1 : int, optional
    Axes to be used as the first and second axis of the 2-D sub-arrays
    from which the diagonals should be taken. Defaults are the first two
    axes of `a`.
axis2 : int, optional
    Axes to be used as the first and second axis of the 2-D sub-arrays
    from which the diagonals should be taken. Defaults are the first two
    axes of `a`.
dtype : dtype, optional
    Determines the data-type of the returned array and of the accumulator
    where the elements are summed. If dtype has the value None and `a` is
    of integer type of precision less than the default integer
    precision, then the default integer precision is used. Otherwise,
    the precision is the same as that of `a`.
out : ndarray, optional
    Array into which the output is placed. Its type is preserved and
    it must be of the right shape to hold the output.

Returns
-------
sum_along_diagonals : ndarray
    If `a` is 2-D, the sum along the diagonal is returned.  If `a` has
    larger dimensions, then an array of sums along diagonals is returned.

See Also
--------
diag, diagonal, diagflat

Examples
--------
>>> import numpy as np
>>> np.trace(np.eye(3))
3.0
>>> a = np.arange(8).reshape((2,2,2))
>>> np.trace(a)
array([6, 8])
>>> a = np.arange(24).reshape((2,2,2,3))
>>> np.trace(a).shape
(2, 3)
