nnz在torch.sparse_coo_tensor的输出中意味着什么(索引,值,大小=无,dtype =无,设备=无,requires_grad = False)?

时间:2019-06-18 02:36:20

标签: pytorch sparse-matrix

nnz在以下pytorch函数的输出中是什么意思

torch.sparse_coo_tensor(索引,值,大小=无,dtype =无,设备=无,requires_grad = False)

可以在此链接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)

1 个答案:

答案 0 :(得分:1)

nnz平均数非零元素。在此示例中,nnz = 3。