mindspore.ops.masked_fill
- mindspore.ops.masked_fill(input_x, mask, value)[source]
Fills elements of Tensor with value where mask is True. The shapes of input_x and mask need to be the same or broadcastable.
- Parameters
- Returns
Tensor, has the same type and shape as input_x.
- Raises
TypeError – If dtype of mask is not bool.
TypeError – If input_x or mask is not a Tensor.
ValueError – If the shapes of input_x and mask could not be broadcast.
TypeError – If dtype of input_x or value is not one of float16, float32, int8, int32.
TypeError – If dtype of value is different from that of input_x.
TypeError – If value is neither float number nor Tensor.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> input = Tensor(np.array([1., 2., 3., 4.]), mindspore.float32) >>> mask = Tensor(np.array([True, True, False, True]), mindspore.bool_) >>> output = ops.masked_fill(input, mask, 0.5) >>> print(output) [0.5 0.5 3. 0.5]