latest (dev)
Copy
Latest development documentation · Updated 2026-10-15
tensorplay.functional.count_nonzero
- tensorplay.functional.count_nonzero(input, dim=None) Tensor[source]
Counts the number of non-zero values in the tensor
inputalong the givendim. If no dim is specified then all non-zeros in the tensor are counted.- Parameters:
Example:
>>> x = tensorplay.zeros(3,3) >>> x[tensorplay.randn(3,3) > 0.5] = 1 >>> x tensor([[0., 1., 1.], [0., 0., 0.], [0., 0., 1.]]) >>> tensorplay.count_nonzero(x) tensor(3) >>> tensorplay.count_nonzero(x, dim=0) tensor([0, 1, 2])
Help improve this page
Found an error, an unclear step, or a missing example?
Was this page helpful?

