torch.count_nonzero
-
torch.count_nonzero(input, dim=None) → Tensor -
Подсчитывает количество ненулевых значений в тензоре
inputвдоль указанногоdim. Если dim не указан, подсчитываются все ненулевые значения в тензоре.- Параметры
Пример:
>>> 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])
© 2024, PyTorch Contributors
PyTorch has a BSD-style license, as found in the LICENSE file.
https://pytorch.org/docs/2.1/generated/torch.count_nonzero.html