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)