矩阵上的Scipy线性化器

2024-10-02 10:33:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个线性函数A,它的输入和输出是(m,n)numpy数组。我想用CG或GMRES来解决一个系统A(x) = b。有没有什么方法可以定义scipyLinearOperator,而不改变函数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 )

Tags: 方法函数importnumpy定义系统asnp

热门问题