问题描述
在一个scipy程序中,我正在创建一个带有5个对角线的dia_matrix(稀疏矩阵类型).中心对角线+1& -1对角线和+4& -4对角线(通常>> 4,但是原理相同),即我具有以下形式的典型PDE系统矩阵:
In a scipy program I'm creating a dia_matrix (sparse matrix type) with 5 diagonals. The centre diagonal the +1 & -1 diagonals and the +4 & -4 diagonals (usually >> 4, but the principle is the same), i.e. I have a typical PDE system matrix of the form:
[ a0 b0 0 0 0 d0 0 0 0 ... 0.0 ]
[ c1 a1 b1 0 0 0 d1 0 0 ... 0.0 ]
[ 0 c2 a2 b2 0 0 0 d2 0 ... 0.0 ]
[ 0 0 c3 a3 b3 0 0 0 d3 ... 0.0 ]
[ 0 0 0 c4 a4 b4 0 0 0 ... 0.0 ]
[ e5 0 0 0 c5 a5 b5 0 0 ... 0.0 ]
[ : : : : : : : : : : : ]
[ 0 0 0 0 0 0 0 0 0 ... aN ]
当我使用scipy.linalg.dsolve.spsolve()求解矩阵方程时,它可以工作,但我收到以下报告给我
When I use scipy.linalg.dsolve.spsolve() to solve the matrix equation it works but I get the following reported back to me
>>> SparseEfficiencyWarning: spsolve requires CSC or CSR matrix format
warn('spsolve requires CSC or CSR matrix format', SparseEfficiencyWarning)
如果spsolve()对于解决稀疏矩阵类型dia_matrix的效率不高,那么我应该使用什么?
If spsolve() is not efficient for solving the sparse matrix type dia_matrix's then what should I be using?
推荐答案
这个答案有点迟了,但我希望您发现添加了:
I'm a bit late with this answer, but I hope you found that adding:
from scipy.linalg import solve_banded
允许您使用DIA矩阵,而不必求助于CSR或CSC.
Allows you to use a DIA matrix rather than having to resort to CSR or CSC.
这篇关于Scipy稀疏dia_matrix解算器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!