简体   繁体   English

压缩稀疏列(CSC)或压缩稀疏行(CSR)稀疏矩阵?

[英]Compressed Sparse Column (CSC) or Compressed Sparse Row (CSR) sparse matrix?

I have a design matrix I'm converting in a sparse matrix using the scipy module 我有一个设计矩阵,我正在使用scipy模块在稀疏矩阵中进行转换

It have many rows and only few columns 它有很多行,只有很少的列

With this shape, is it better to use the CSC or the CSR design ? 有了这种形状,使用CSC或CSR设计会更好吗? Or are they strictly equivalent for the execution speed ? 或者他们是否严格等同于执行速度?

Basically, it looks like this example : (But there is many more rows in the true one) 基本上,它看起来像这个例子:(但真正的行中还有更多的行)

在此输入图像描述

Thanks ! 谢谢 !

You can readily convert one format to the other ( .tocsc() , .tocsr() ). 您可以轻松地将一种格式转换为另一种格式( .tocsc() .tocsr() )。 In fact MT for a csr just creates a csc with the same data. 事实上, csr MT只是创建了一个具有相同数据的csc

In a number of cases sparse functions convert a matrix to another format to perform certain actions. 在许多情况下, sparse函数将矩阵转换为另一种格式以执行某些操作。 In other cases it gives an 'efficiency' warning if the format isn't the best. 在其他情况下,如果格式不是最好的,它会给出“效率”警告。 (beware, warnings appear only once per run.) (注意,警告每次运行只出现一次。)

If you are iterating over columns, or selecting mostly by column, csc is better with converse true for csr . 如果您正在迭代列,或者主要按列选择,那么对于csrcsc会更好,反之亦然。 For math, matrix products and such, they are equivalent. 对于数学,矩阵产品等,它们是等价的。

Create the matrix one way, and do a few timing tests for typical operations. 单向创建矩阵,并对典型操作进行一些时序测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM