Table of Contents
Shortcuts

# torch.Tensor.to_sparse_csc

Tensor.to_sparse_csc() → Tensor

  Convert a tensor to compressed column storage (CSC) format. Except for strided tensors, only works with 2D tensors. If the `self` is strided, then the number of dense dimensions could be specified, and a hybrid CSC tensor will be created, with dense_dim dense dimensions and self.dim() - 2 - dense_dim batch dimension.

  Parameters:

    dense_dim (int, optional) – Number of dense dimensions of the resulting CSC tensor. This argument should be used only if `self` is a strided tensor, and must be a value between 0 and dimension of `self` tensor minus two.

  Example:

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

      >>> dense = torch.zeros(3, 3, 1, 1)
      >>> dense[0, 0] = dense[1, 2] = dense[2, 1] = 1
      >>> dense.to_sparse_csc(dense_dim=2)
      tensor(ccol_indices=tensor([0, 1, 2, 3]),
             row_indices=tensor([0, 2, 1]),
             values=tensor([[[1.]],

                            [[1.]],

                            [[1.]]]), size=(3, 3, 1, 1), nnz=3,
             layout=torch.sparse_csc)

## Docs

Access comprehensive developer documentation for PyTorch

View Docs

## Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

## Resources

Find development resources and get your questions answered

View Resources

To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.