torch.Tensor.col_indices¶
- Tensor.col_indices() IntTensor ¶
当
self
是布局为sparse_csr
的稀疏 CSR 张量时,返回包含self
张量的列索引的张量。col_indices
张量的形状严格为 (self
.nnz()),类型为int32
或int64
。当使用诸如稀疏矩阵乘法的 MKL 例程时,必须使用int32
索引以避免向下转换并可能丢失信息。- 示例:
>>> csr = torch.eye(5,5).to_sparse_csr() >>> csr.col_indices() tensor([0, 1, 2, 3, 4], dtype=torch.int32)