pytorch / 2 / generated / torch.tensor.to_sparse_coo.html

torch.Tensor.to_sparse_coo

Tensor.to_sparse_coo() [source]

Convert a tensor to coordinate format.

Examples:

>>> dense = torch.randn(5, 5)
>>> sparse = dense.to_sparse_coo()
>>> sparse._nnz()
25

© 2024, PyTorch Contributors
PyTorch has a BSD-style license, as found in the LICENSE file.
https://pytorch.org/docs/2.1/generated/torch.Tensor.to_sparse_coo.html