mindspore.Tensor.masked_fill_
- Tensor.masked_fill_(mask, value) Tensor
Fills elements of self Tensor with value where mask is True. The shapes of self and mask need to be the same or broadcastable.
Warning
This is an experimental API that is subject to change or deletion.
- Parameters
- Returns
Tensor.
- Raises
- Supported Platforms:
Ascend
Examples
>>> import mindspore >>> from mindspore import ops >>> x = ops.zeros((3, 3)) >>> print(x) [[0. 0. 0.] [0. 0. 0.] [0. 0. 0.]] >>> mask = mindspore.Tensor([[True, False, False], [True, False, False], [True, False, False]]) >>> output = x.masked_fill_(mask, 1.0) >>> print(output) [[1. 0. 0.] [1. 0. 0.] [1. 0. 0.]] >>> print(x) [[1. 0. 0.] [1. 0. 0.] [1. 0. 0.]]