mindspore.mint.masked_select

View Source On Gitee
mindspore.mint.masked_select(input, mask)[source]

Return a new 1-D tensor which indexes the input tensor according to the boolean mask.

Support broadcast.

Parameters
Returns

Tensor

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> import numpy as np
>>> x = mindspore.tensor(np.array([1, 2, 3, 4]), mindspore.int64)
>>> mask = mindspore.tensor(np.array([1, 0, 1, 0]), mindspore.bool_)
>>> output = mindspore.mint.masked_select(x, mask)
>>> print(output)
[1 3]