torch.Tensor.crow_indices¶
- Tensor.crow_indices() IntTensor¶
當
self是一個佈局為sparse_csr的稀疏 CSR tensor 時,返回包含selftensor 壓縮行索引的 tensor。crow_indicestensor 的形狀嚴格為 (self.size(0) + 1),型別為int32或int64。當使用 MKL 例程(例如稀疏矩陣乘法)時,需要使用int32索引,以避免向下轉型並可能丟失資訊。- 示例:
>>> csr = torch.eye(5,5).to_sparse_csr() >>> csr.crow_indices() tensor([0, 1, 2, 3, 4, 5], dtype=torch.int32)