我有一个线性函数A
,其输入和输出是(m,n)
numpy数组。我想使用CG或GMRES来解决系统A(x) = b
。有没有什么方法可以定义scipy LinearOperator
而不重塑我的函数A
中的输入和输出?
示例:
import numpy as np
import scipy.sparse.linalg as linalg
a = np.array( [ [1,2] , [3,4] ] )
def A(v):
return a * v
# I want to do this but this fails. Any other
# solution that doesn't involve reshaping?
lin_op = linalg.LinearOperator( ((2,2),(2,2)), matvec=A )