mindspore.ops.Select
- class mindspore.ops.Select[source]
Returns the selected elements, either from input
or input , depending on the condition.Given a tensor as input, this operation inserts a dimension of 1 at the dimension, it was invalid when both math: ‘x’ and math: ‘y’ are none. Keep in mind that the shape of the output tensor can vary depending on how many true values are in the input. Indexes are output in row-first order.
The conditional tensor acts as an optional compensation (mask), which determines whether the corresponding element / row in the output must be selected from
(if true) or (if false) based on the value of each element.It can be defined as:
If condition is a vector, then
and are higher-dimensional matrices, then it chooses to copy that row (external dimensions) from and . If condition has the same shape as and , you can choose to copy these elements from and .- Inputs:
input_cond (Tensor[bool]) - The shape is
. The condition tensor, decides which element is chosen.input_x (Tensor) - The shape is
. The first input tensor.input_y (Tensor) - The shape is
. The second input tensor.
- Outputs:
Tensor, has the same shape as input_x. The shape is
.
- Raises
TypeError – If input_x or input_y is not a Tensor.
ValueError – If shape of input_x is not equal to shape of input_y or shape of input_cond.
- 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.]