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)