fn

masked_select

Tensor
masked_select(input: Tensor, mask: Tensor)
source

Return a 1-D tensor of elements where mask is True.

The mask must be broadcast-compatible with input. The output is always rank 1 regardless of input rank — ordering follows row-major traversal.

Parameters

inputTensor
Source tensor.
maskTensor
Boolean tensor broadcastable to input.

Returns

Tensor

1-D tensor of length mask.sum().item().

Notes

Because the output size is data-dependent this operation may force a host round-trip on accelerator backends; prefer where when a fixed-shape result is acceptable.

Examples

>>> import lucid
>>> x = lucid.tensor([[1, 2], [3, 4]])
>>> m = x > 2
>>> lucid.masked_select(x, m)
Tensor([3, 4])