Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does nnz in mean in the output of torch.sparse_coo_tensor(indices, values, size=None, dtype=None, device=None, requires_grad=False)?

What does nnz mean in the output of below pytorch function

torch.sparse_coo_tensor(indices, values, size=None, dtype=None, device=None, requires_grad=False)

It can be found at this link https://pytorch.org/docs/stable/torch.html


i = torch.tensor([[0, 1, 1],
                      [2, 0, 2]])

v = torch.tensor([3, 4, 5], dtype=torch.float32)

torch.sparse_coo_tensor(i, v, [2, 4],
                            dtype=torch.float64,
                            device=torch.device('cuda:0'))

tensor(indices=tensor([[0, 1, 1],
                       [2, 0, 2]]),
       values=tensor([3., 4., 5.]),
       device='cuda:0', size=(2, 4), nnz=3, dtype=torch.float64,
       layout=torch.sparse_coo)

like image 238
Bhanujeet Choudhary Avatar asked May 04 '26 12:05

Bhanujeet Choudhary


1 Answers

nnz mean number non zero elements. In this example nnz = 3.

like image 164
Mykola Lys Avatar answered May 07 '26 07:05

Mykola Lys



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!