mindspore.ops.Select
- class mindspore.ops.Select[source]
The conditional tensor determines whether the corresponding element in the output must be selected from x (if True) or y (if False) based on the value of each element.
It can be defined as:
\[\begin{split}out_i = \begin{cases} x_i, & \text{if } cond_i \\ y_i, & \text{otherwise} \end{cases}\end{split}\]- Inputs:
cond (Tensor[bool]): The condition tensor, decides which element is chosen. The shape is \((x_1, x_2, ..., x_N, ..., x_R)\).
x (Tensor): The first Tensor to be selected. The shape is \((x_1, x_2, ..., x_N, ..., x_R)\).
y (Tensor): The second Tensor to be selected. The shape is \((x_1, x_2, ..., x_N, ..., x_R)\).
- Outputs:
Tensor, has the same shape as cond.
- Raises
TypeError – If x or y is not a Tensor.
ValueError – The shape of inputs are different.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> from mindspore import Tensor, ops >>> # Both inputs are Tensor >>> select = ops.Select() >>> cond = Tensor([True, False]) >>> x = Tensor([2,3], mindspore.float32) >>> y = Tensor([1,2], mindspore.float32) >>> output = select(cond, x, y) >>> print(output) [2. 2.]