mindspore.ops.select
- mindspore.ops.select(condition, input, other)[source]
The conditional tensor determines whether the corresponding element in the output must be selected from input (if True) or other (if False) based on the value of each element.
It can be defined as:
- Parameters
- Returns
Tensor
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> # case1: Both `input` and `other` are tensor >>> cond = mindspore.tensor([True, False]) >>> x = mindspore.tensor([2,3], mindspore.float32) >>> y = mindspore.tensor([1,2], mindspore.float32) >>> output1 = mindspore.ops.select(cond, x, y) >>> print(output1) [2. 2.] >>> # case2: Both `input` and `other` are number >>> output2 = mindspore.ops.select(cond, input=1, other=2) >>> print(output2) [1 2] >>> # case3: `input` is tensor and `other` is number >>> output3 = mindspore.ops.select(cond, x, other=3) >>> print(output3) [2. 3.]