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)