一次操作改变稀疏结构

2024-06-10 04:57:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个A格式的矩阵coo(它是从scipy.sparse.bmat创建的):

A
<80000x80000 sparse matrix of type '<class 'numpy.float64'>'
    with 278480 stored elements in COOrdinate format>

我想

  1. 更改此矩阵特定行中的所有值
  2. 对改变矩阵上的某些gspsolve(A, g)

现在,我无法更改coo格式的行。以下工作:

^{pr2}$

但我会得到

SparseEfficiencyWarning: Changing the sparsity structure of a csr_matrix is expensive. lil_matrix is more efficient.
  SparseEfficiencyWarning)

现在,据我所知,lil_matrix在解线性代数时效率低下,所以即使我将稀疏结构改为lil,我也会/应该在之后改回csr或{}。在

总的来说,这值得吗?我不想快速测试我在这里所做的每一个操作:有没有经验法则来说明“改变稀疏性”与“行切片”与“算术运算”的代价有多高?程序员通常如何处理这类问题?在


Tags: ofnumpyis格式type矩阵scipymatrix