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:

outi={xi,if conditioniyi,otherwise
Inputs:
  • condition (Tensor[bool]) - The condition tensor, decides which element is chosen. The shape is (x1,x2,...,xN,...,xR).

  • x (Tensor) - The first tensor to be selected and the shape is (x1,x2,...,xN,...,xR).

  • y (Tensor) - The second tensor to be selected and the shape is (x1,x2,...,xN,...,xR).

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.]