fn
nonzero
→Tensornonzero(input: Tensor)Return the indices of all non-zero (or True) elements.
The output is a 2-D int64 tensor of shape (N, input.ndim)
where N is the number of non-zero entries — each row is one
multi-index.
Parameters
inputTensorSource tensor.
Returns
Tensor2-D int64 tensor of multi-indices.
Notes
Because the output size is data-dependent this op forces a CPU
round-trip on accelerator backends. For mask-style use cases
prefer where or masked_select.
Examples
>>> import lucid
>>> x = lucid.tensor([[0, 1], [2, 0]])
>>> lucid.nonzero(x)
Tensor([[0, 1],
[1, 0]])