Scipy稀疏矩阵-不同实现的目的和用法 [英] Scipy sparse matrices - purpose and usage of different implementations

查看:85
本文介绍了Scipy稀疏矩阵-不同实现的目的和用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Scipy具有许多可用的稀疏矩阵类型.这些类型之间最重要的区别是什么,它们的预期用途有什么区别?

Scipy has many different types of sparse matrices available. What are the most important differences between these types, and what is the difference in their intended usage?

我正在基于Matlab中的示例代码 1 用python开发代码.该代码的一部分使用稀疏矩阵-在Matlab中似乎只有一种(讨厌的)类型,而我试图找出在python中应该使用哪种类型的 2 .

I'm developing a code in python based on a sample code1 in Matlab. One section of the code utilizes sparse matrices - which seem to have a single (annoying) type in Matlab, and I'm trying to figure out which type I should use2 in python.

1:这是针对一堂课的.大多数人都在Matlab中进行该项目,但显然,我喜欢创建不必要的工作和混乱.

1: This is for a class. Most people are doing the project in Matlab, but I like to create unnecessary work and confusion --- apparently.

2:这是一个学术问题:我的代码可以与'

2: This is an academic question: I have the code working properly with the 'CSR' format, but I'm interesting in knowing what the optimal usages are.

推荐答案

很抱歉,如果我没有完全回答这个问题,但希望我能提供一些见识.

Sorry if I'm not answering this completely enough, but hopefully I can provide some insight.

CSC(压缩稀疏列)和CSR(压缩稀疏行)更加紧凑和高效,但难以从头开始"构建. Coo(坐标)和DOK(密钥字典)易于构建,然后可以通过matrix.tocsc()matrix.tocsr()转换为CSC或CSR.

CSC (Compressed Sparse Column) and CSR (Compressed Sparse Row) are more compact and efficient, but difficult to construct "from scratch". Coo (Coordinate) and DOK (Dictionary of Keys) are easier to construct, and can then be converted to CSC or CSR via matrix.tocsc() or matrix.tocsr().

通常,因为CSC存储为列数组及其在每一行的值,所以CSC在访问列向量或列操作时效率更高.

CSC is more efficient at accessing column-vectors or column operations, generally, as it is stored as arrays of columns and their value at each row.

CSR矩阵相反;存储为行数组及其在每一列的值,并且在访问行向量或行操作时效率更高.

CSR matrices are the opposite; stored as arrays of rows and their values at each column, and are more efficient at accessing row-vectors or row operations.

这篇关于Scipy稀疏矩阵-不同实现的目的和用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆