【发布时间】:2018-03-23 05:53:27
【问题描述】:
我要解决由大型稀疏矩阵组成的线性系统。
我一直在使用 scipy.sparse 库及其 linalg 子库来执行此操作,但我无法让某些线性求解器工作。
这是一个为我重现问题的工作示例:
from numpy.random import random
from scipy.sparse import csc_matrix
from scipy.sparse.linalg import spsolve, minres
N = 10
A = csc_matrix( random(size = (N,N)) )
A = (A.T).dot(A) # force the matrix to be symmetric, as required by minres
x = csc_matrix( random(size = (N,1)) ) # create a solution vector
b = A.dot(x) # create the RHS vector
# verify shapes and types are correct
print('A', A.shape, type(A))
print('x', x.shape, type(x))
print('b', b.shape, type(b))
# spsolve function works fine
sol1 = spsolve(A, b)
# other solvers throw a incompatible dimensions ValueError
sol2 = minres(A, b)
运行它会产生以下错误
raise ValueError('A and b have incompatible dimensions')
ValueError: A and b have incompatible dimensions
对于minres 的调用,尽管尺寸明显是 兼容的。 scipy.sparse.linalg 中的其他求解器,例如 cg、lsqr 和 gmres 都抛出相同的错误。
这是在带有 SciPy 0.19 的 python 3.6.1 上运行的。
有人知道这里发生了什么吗?
谢谢!
【问题讨论】:
标签: python scipy sparse-matrix linear-algebra