# tensorplay.functional.count_nonzero Source: https://www.tensorplay.cn/docs/generated/tensorplay.functional.count_nonzero.html ```python tensorplay.functional.count_nonzero(input, dim=None) → Tensor ``` Counts the number of non-zero values in the tensor input along the given dim. If no dim is specified then all non-zeros in the tensor are counted. Parameters: - input ([Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)) – the input tensor. - dim ([int](https://docs.python.org/3/builtins/functions.html#int) or [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple) of ints, optional) – Dim or tuple of dims along which to count non-zeros. 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]) ```