latest (dev)
Copy
Latest development documentation · Updated 2026-10-15
tensorplay.functional.argwhere
- tensorplay.functional.argwhere(input) Tensor[source]
Returns a tensor containing the indices of all non-zero elements of
input. Each row in the result contains the indices of a non-zero element ininput. The result is sorted lexicographically, with the last index changing the fastest (C-style).If
inputhas dimensions, then the resulting indices tensoroutis of size , where is the total number of non-zero elements in theinputtensor.Note
This function is similar to NumPy’s argwhere.
When
inputis on CUDA, this function causes host-device synchronization.- Parameters:
{input}
Example:
>>> t = tensorplay.tensor([1, 0, 1]) >>> tensorplay.argwhere(t) tensor([[0], [2]]) >>> t = tensorplay.tensor([[1, 0, 1], [0, 1, 1]]) >>> tensorplay.argwhere(t) tensor([[0, 0], [0, 2], [1, 1], [1, 2]])
Help improve this page
Found an error, an unclear step, or a missing example?
Was this page helpful?

