mindspore/docs/api/api_python/mint/mindspore.mint.func_where.rst

29 lines
1.2 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.mint.where
====================
.. py:function:: mindspore.mint.where(condition, input, other) -> Tensor
返回一个TensorTensor的元素从 `input``other` 中根据 `condition` 选择。
.. math::
output_i = \begin{cases} input_i,\quad &if\ condition_i \\ other_i,\quad &otherwise \end{cases}
参数:
- **condition** (Tensor[bool]) - 如果是 ``True`` ,选取 `input` 中的元素,否则选取 `other` 中的元素。
- **input** (Union[Tensor, Scalar]) - 在 `condition```True`` 的索引处选择的值。
- **other** (Union[Tensor, Scalar]) - 当 `condition```False`` 的索引处选择的值。
返回:
Tensor其中的元素从 `input``other` 中选取。
异常:
- **TypeError** - 如果 `condition` 不是Tensor。
- **TypeError** - 如果 `input``other` 都是常量。
- **ValueError** - `condition``input``other` 不能互相广播。
.. py:function:: mindspore.mint.where(condition) -> Tensor
:noindex:
与接口 :func:`mindspore.ops.nonzero` 在输入为 `condition``as_tuple` 为True时一致。