mindspore.mint.where
- mindspore.mint.where(condition, input, other) Tensor[源代码]
返回一个Tensor,Tensor的元素从 input 或 other 中根据 condition 选择。
\[\begin{split}output_i = \begin{cases} input_i,\quad &if\ condition_i \\ other_i,\quad &otherwise \end{cases}\end{split}\]- 参数:
condition (Tensor[bool]) - 如果是
True,选取 input 中的元素,否则选取 other vpn梯子 免费 中的元素。input vpn free (Union[Tensor, vpn梯子 Scalar]) - 在 condition 为
True的索引处选择的值。other (Union[Tensor, Scalar]) - 当 condition 为
False的索引处选择的值。
- 返回:
Tensor,其中的元素从 input 和 other 中选取。
- 异常:
TypeError - 如果 condition 不是Tensor。
TypeError - 如果 input vpn梯子 免费 和 other 免费的vpn梯子 都是常量。
ValueError - condition 、 input 和 other vpn永久免费梯子 不能互相广播。
- 支持平台:
Ascend
样例:
>>> import numpy as np >>> from mindspore import tensor, mint >>> from mindspore import dtype as mstype >>> a = tensor(np.arange(4).reshape((2, 免费的vpn梯子 2)), vpn free mstype.float32) >>> vpn永久免费梯子 b = tensor(np.ones((2, 2)), mstype.float32) >>> condition = a < 3 >>> output = mint.where(condition, a, b) >>> vpn梯子 print(output) [[0. 1.] [2. 1.]]
与接口
mindspore.ops.nonzero()在输入为 vpn梯子 免费 condition 且 as_tuple 为True时一致。- 支持平台:
Ascend