mindspore.Tensor.select
- Tensor.select(dim, index) Tensor
Slices the self tensor along the selected dimension at the given index.
Warning
This is an experimental API that is subject to change or deletion.
- Parameters
- Returns
Tensor.
- Supported Platforms:
Ascend
Examples
>>> import mindspore >>> from mindspore import Tensor >>> input = Tensor([[2, 3, 4, 5],[3, 2, 4, 5]]) >>> y = Tensor.select(input, 0, 0) >>> print(y) [2 3 4 5]
- Tensor.select(condition, y) Tensor
The conditional tensor determines whether the corresponding element in the output must be selected from input (if True) or y (if False) based on the value of each element.
It can be defined as:
\[\begin{split}out_i = \begin{cases} self_i, & \text{if } condition_i \\ other_i, & \text{otherwise} \end{cases}\end{split}\]- Parameters
condition (Tensor[bool]) – The condition tensor, decides which element is chosen. The shape is \((x_1, x_2, ..., x_N, ..., x_R)\).
y (Union[Tensor, int, float]) – The second Tensor to be selected. If other is a Tensor, its shape should be or be braodcast to \((x_1, x_2, ..., x_N, ..., x_R)\). If other is int or float, it will be casted to int32 or float32, and broadcast to the same shape as self. There must be at least one Tensor between self and other.
- Returns
Tensor, has the same shape as condition.
- Raises
TypeError – If y is not a Tensor, int or float.
ValueError – The shape of inputs cannot be broadcast.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> from mindspore import Tensor >>> # Both input are Tensor >>> cond = Tensor([True, False]) >>> x = Tensor([2,3], mindspore.float32) >>> y = Tensor([1,2], mindspore.float32) >>> output = Tensor.select(x, cond, y) >>> print(output) [2. 2.]