mindspore/docs/api/api_python/numpy/mindspore.numpy.diagonal.rst

19 lines
1.3 KiB
ReStructuredText
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

mindspore.numpy.diagonal
=================================
.. py:function:: mindspore.numpy.diagonal(a, offset=0, axis1=0, axis2=1)
返回数组指定的对角线。
如果 ``a`` 是二维,则返回具有给定 ``offset````a`` 的对角线,形如 ``a[i, i+offset]`` 的元素的集合。如果 ``a`` 具有两个以上的维度,则使用 ``axis1````axis2`` 指定的轴来确定返回对角线的二维子数组。可以通过移除 ``axis1````axis2`` 并在右边附加等于结果对角线大小的索引来确定结果数组的shape。
参数:
- **a** (Tensor) - 输入数据,用于从中获取对角线的数组。
- **offset** (int, 可选) - 对角线与主对角线的偏移量。可以是正的或负的。默认主对角线。
- **axis1** (int, 可选) - 二维子数组的第一个轴。默认为第一个轴0
- **axis2** (int, 可选) - 二维子数组的第二个轴。默认为第二个轴。
返回:
Tensor如果传递的数组 ``a`` 是二维数组,则返回包含对角线元素的一维数组。对于三维数组或更多维数组,将删除 ``axis1````axis2`` 指定的轴,并将两个参数中较小的一个添加到最后一个轴。
异常:
- **ValueError** - 如果输入的数据少于两个维度。