latest (dev)
Copy
Latest development documentation · Updated 2026-10-15
tensorplay.functional.is_nonzero
- tensorplay.functional.is_nonzero(input)[source]
Returns True if the
inputis a single element tensor which is not equal to zero after type conversions. i.e. not equal totensorplay.tensor([0.])ortensorplay.tensor([0])ortensorplay.tensor([False]). Throws aRuntimeErroriftensorplay.numel() != 1(even in case of sparse tensors).- Parameters:
input (Tensor) – the input tensor.
Examples:
>>> tensorplay.is_nonzero(tensorplay.tensor([0.])) False >>> tensorplay.is_nonzero(tensorplay.tensor([1.5])) True >>> tensorplay.is_nonzero(tensorplay.tensor([False])) False >>> tensorplay.is_nonzero(tensorplay.tensor([3])) True >>> tensorplay.is_nonzero(tensorplay.tensor([1, 3, 5])) Traceback (most recent call last): ... RuntimeError: Boolean value of Tensor with more than one value is ambiguous >>> tensorplay.is_nonzero(tensorplay.tensor([])) Traceback (most recent call last): ... RuntimeError: Boolean value of Tensor with no values is ambiguous
Help improve this page
Found an error, an unclear step, or a missing example?
Was this page helpful?

