Search code examples
pythonscipysparse-matrixanaconda

What happens to my scipy.sparse.linalg.eigs?


I use python 2.7.8 with the Anaconda distribution and I have problems with scipy. Let A be a sparse matrix; I want to calculate its eigenvalues but if I write:

import scipy
scipy.sparse.linalg.eigs(A)

I get the error

    Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable

What is the problem? (The version of scipy is 0.15.1)


Solution

  • Does this work for you?

    from scipy import sparse
    import scipy.sparse.linalg as sp_linalg
    
    B = np.random.rand(10,10)
    A_dense = np.dot(B.T, B)
    A_sparse = sparse.lil_matrix(A_dense)
    sp_linalg.eigs(A_sparse, 3)
    

    It seems that you have to explicitly import the submodules. scipy does not load those per default.