mindspore.numpy.where
- mindspore.numpy.where(condition, x=None, y=None)[源代码]
Returns elements chosen from x or y depending on condition.
Note
As nonzero is not supported, both x and y must be provided Tensor
input.
- Parameters
- Returns
Tensor or scalar, with elements from x where condition is True, and elements from y elsewhere.
- Raises
ValueError – If operands cannot be broadcast.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> 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]]]