>>> import numpy as np
>>> import torch
>>> f=torch.tensor([[1,0,2,3],[0,0,3,4],[8,0,2,1],[6,0,1,0]])
>>> f
tensor([[1, 0, 2, 3],
[0, 0, 3, 4],
[8, 0, 2, 1],
[6, 0, 1, 0]])
>>> torch.count_nonzero(f)
tensor(10)
>>> torch.numel(f)-torch.count_nonzero(f)
tensor(6)
In the above example, tensor 'f' has 6 zeroes and 10 non-zero elements.