mindspore/docs/api/api_python/ops/mindspore.ops.NthElement.rst

24 lines
1.3 KiB
ReStructuredText
Raw 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.ops.NthElement
========================
.. py:class:: mindspore.ops.NthElement(reverse=False)
寻找并返回输入Tensor最后一维第 :math:`n` 小的值。
如果输入是Vector(rank为1)寻找第n小的值并以Scalar Tensor类型输出结果。
对于Matrixrank大于1计算最后一维每一行各自可以看作一个Vector第n小的值。因此返回值 `values` 的shape满足 `values`.shape = `input`.shape[:-1]。
参数:
- **reverse** (bool可选) - 可选参数如果设为True则寻找第 :math:`n` 大的值如果设为False则寻找第n小的值。默认值False。
输入:
- **input** (Tensor) - 一维或者更高维度的Tensor最后一维的大小必须大于等于 :math:`n+1`
- **n** (Union[int, Tensor]) - 如果 :math:`n` 为Tensor则必须是0维的数据类型是int32。 :math:`n` 的有效范围是::math:`[0, input.shape[-1])`
输出:
- **values** (Tensor) - 其shape满足 `values`.shape = `input`.shape[:-1],数据类型与 `input` 一致。
异常:
- **TypeError** - `input` 的数据类型不在有效类型列表内。
- **TypeError** - `n` 不是int32或者Tensor。
- **ValueError** - `n` 不在 :math:`[0, input.shape[-1])` 范围内。