mindspore.numpy.where
- mindspore.numpy.where(condition, x=None, y=None)[源代码]
Returns elements chosen from x or y depending on condition.
说明
As nonzero is not supported, both x and y must be provided Tensor
input.
- 参数
- 返回
Tensor or scalar, with elements from x where condition is True, and elements from y elsewhere.
- 异常
ValueError – If operands cannot be broadcast.
- Supported Platforms:
Ascend
GPU
CPU
样例
>>> import mindspore.numpy as np >>> condition = np.full((1, 1, 2), [False, True]) >>> x = np.full((1, 3, 2), 5) >>> y = np.full((2, 1, 1), 7) >>> output = np.where(condition, x, y) >>> print(output) [[[7 5] [7 5] [7 5]] [[7 5] [7 5] [7 5]]]