矩阵AX=B求解X时,需要调用scipy的函数scipy.sparse.linalg.cg
python中直接from scipy import linalg
在代码中,调用为x=linalg.cg(A,B),运行后报错:
AttributeError: module 'scipy.sparse' has no attribute 'linalg'
查询原因发现是python的import需要moudule的真实名字,也就是直接import module,因此更改代码为:
from scipy.sparse.linalg import cg
x=cg(A,B)
更改后运行成功.