mindspore.Tensor.masked_scatter
- Tensor.masked_scatter(mask, x)[source]
Updates the value in the "self Tensor" with the tensor value according to the mask, and returns a Tensor. The shape of mask and the "self Tensor" must be the same or mask is broadcastable.
Warning
This is an experimental API that is subject to change or deletion.
- Parameters
- Returns
Tensor, with the same type and shape as the "self Tensor".
- Raises
TypeError – If mask or x is not a Tensor.
TypeError – If data type of the "self Tensor" is not be supported.
TypeError – If dtype of mask is not bool.
TypeError – If the dim of the "self Tensor" less than the dim of mask.
ValueError – If mask can not be broadcastable to the "self Tensor".
ValueError – If the number of elements in x is less than the number required for the updates.
- Supported Platforms:
Ascend
CPU
Examples
>>> import numpy as np >>> import mindspore >>> from mindspore import Tensor >>> x = Tensor(np.array([1., 2., 3., 4.]), mindspore.float32) >>> mask = Tensor(np.array([True, True, False, True]), mindspore.bool_) >>> tensor = Tensor(np.array([5., 6., 7.]), mindspore.float32) >>> output = x.masked_scatter(mask, tensor) >>> print(output) [5. 6. 3. 7.]