【发布时间】:2015-02-12 10:21:55
【问题描述】:
我有一个使用 scipy.sparse.linalg.gmres 解决稀疏线性系统的简单代码
W, S = load_data()
M = normalize(W.T.astype('float64'),'l1')
S = normalize(S.astype('float64'),'l1')
rhs = S[cat_id,:].T
print M.shape
print rhs.shape
p = gmres(M, rhs)
函数 load_data 从 matlab 的 .mat 文件中加载两个稀疏矩阵并省略。 输出令人惊讶:
(150495, 150495)
(150495, 1)
Traceback (most recent call last):
File "explain.py", line 54, in <module>
pr(1)
File "explain.py", line 42, in pr
p = gmres(M, rhs)
File "<string>", line 2, in gmres
File "/usr/lib/python2.7/dist-packages/scipy/sparse/linalg/isolve/iterative.py", line 85, in non_reentrant
return func(*a, **kw)
File "/usr/lib/python2.7/dist-packages/scipy/sparse/linalg/isolve/iterative.py", line 418, in gmres
A,M,x,b,postprocess = make_system(A,M,x0,b,xtype)
File "/usr/lib/python2.7/dist-packages/scipy/sparse/linalg/isolve/utils.py", line 78, in make_system
raise ValueError('A and b have incompatible dimensions')
ValueError: A and b have incompatible dimensions
但我已经按照文档运行 gmres
A : {稀疏矩阵、稠密矩阵、LinearOperator}
The real or complex N-by-N matrix of the linear system.b : {数组,矩阵}
Right hand side of the linear system. Has shape (N,) or (N,1).
我只是不明白这段代码有什么问题,希望有任何想法。
【问题讨论】:
-
如何从错误信息到主题行?
标签: python numpy scipy linear-algebra sparse-matrix