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 } condition_i \\ y_i, & \text{otherwise} \end{cases}\end{split}\]
Inputs:
  • condition (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 and the shape is \((x_1, x_2, ..., x_N, ..., x_R)\).

  • y (Tensor) - The second tensor to be selected and the shape is \((x_1, x_2, ..., x_N, ..., x_R)\).

Outputs:

Tensor, has the same shape as condition.

Raises
  • TypeError – If x or y is not a Tensor.

  • ValueError – If shape of the three inputs are different.

Supported Platforms:

Ascend GPU CPU

Examples

>>> select = ops.Select()
>>> input_cond = Tensor([True, False])
>>> input_x = Tensor([2,3], mindspore.float32)
>>> input_y = Tensor([1,2], mindspore.float32)
>>> output = select(input_cond, input_x, input_y)
>>> print(output)
[2. 2.]