scipy.sparse.linalg.eigs使用抽象线性运算符失败

时间:2015-09-28 22:26:00

标签: python scipy linear-algebra linear eigenvalue

当我使用抽象/黑盒线性运算符时,上述函数失败。这是一个最小的例子:

import numpy as np
import scipy.sparse.linalg as la

# Just generate an n X n matrix
n = 9
a = np.random.normal( size = n * n )
a = a.reshape( (n,n) )

# A is a black-box linear operator
def A(v):
    global a   
    return np.dot( a, v )

# If you don't define a shpae for A you get an error
A.shape = ( n,n )

# This works
success = la.eigs( a )

# This throws an error.
failure = la.eigs( A )    

对于带有scipy 0.13.3的python 3.2.2以及带有scipy 0.16.0的python 2.7.3,会发生这种情况。

错误讯息:

File "/home/daon/.local/lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.py", line 1227, in eigs
    matvec = _aslinearoperator_with_dtype(A).matvec
  File "/home/daon/.local/lib/python2.7/site-packages/scipy/sparse/linalg/eigen/arpack/arpack.py", line 885, in _aslinearoperator_with_dtype
    m = aslinearoperator(m)
  File "/home/daon/.local/lib/python2.7/site-packages/scipy/sparse/linalg/interface.py", line 682, in aslinearoperator
    raise TypeError('type not understood')
 TypeError: type not understood

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:1)

好的,这很令人尴尬:只需另外定义Fabric

A

这使得一切正常。