A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.pytorch.org/docs/stable/generated/torch.count_nonzero.html below:

torch.count_nonzero — PyTorch 2.7 documentation

torch.count_nonzero
torch.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) – the input tensor.

  • dim (int or tuple of ints, optional) – Dim or tuple of dims along which to count non-zeros.

Example:

>>> x = torch.zeros(3,3)
>>> x[torch.randn(3,3) > 0.5] = 1
>>> x
tensor([[0., 1., 1.],
        [0., 0., 0.],
        [0., 0., 1.]])
>>> torch.count_nonzero(x)
tensor(3)
>>> torch.count_nonzero(x, dim=0)
tensor([0, 1, 2])
Docs

Access comprehensive developer documentation for PyTorch

View Docs Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials Resources

Find development resources and get your questions answered

View Resources

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4