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

28 lines
1.5 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.ops.NthElement
========================
.. py:class:: mindspore.ops.NthElement(reverse=False)
`ops.NthElement` 从2.8.0版本开始已被弃用,并将在未来版本中被移除。
建议使用 :func:`mindspore.ops.sort` 替代。
寻找并返回输入Tensor最后一维第 `n` 小的值。
- 如果输入是1-D Tensor(即Vector)则找到Vector中第n小的值并将其输出为标量Tensor。
- 如果输入是矩阵或更高维度的输入分别计算每行中的第n小的值或沿着最后一个维度的Vector并输出这些值。因此返回值 `values` 的shape满足 `values`.shape = `input`.shape[:-1]。
参数:
- **reverse** (bool可选) - 可选参数,如果设为 ``True`` ,则寻找第 :math:`n` 大的值,如果设为 ``False`` 则寻找第n小的值。默认值 ``False``
输入:
- **input** (Tensor) - 一维或者更高维度的输入Tensor。
- **n** (Union[int, Tensor]) - 如果 `n` 为Tensor则必须是零维的数据类型是int32。 `n` 的有效范围是::math:`[0, input.shape[-1])` ,其中 :math:`input.shape[-1]``input` 最后一维的size。
输出:
- **values** (Tensor) - 其shape满足 `values`.shape = `input`.shape[:-1],数据类型与 `input` 一致。
异常:
- **TypeError** - `input` 的数据类型不在有效类型列表内。
- **TypeError** - `n` 不是int32或者Tensor。
- **ValueError** - `n` 不在 :math:`[0, input.shape[-1])` 范围内。