The Python Oracle

Scipy LinearOperator dtype unspecified

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Horror Game Menu Looping

--

Chapters
00:00 Scipy Linearoperator Dtype Unspecified
01:41 Accepted Answer Score 4
02:13 Thank you

--

Full question
https://stackoverflow.com/questions/2025...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #numpy #matrix #scipy

#avk47



ACCEPTED ANSWER

Score 4


(This is more of an extended comment than an answer.)

What version of scipy are you using? I'm using scipy 0.13.0. If I don't specify the dtype when I create the LinearOperator, I get the dtype error that you get. But specifying dtype='float64' works for me:

In [1]: import numpy as np

In [2]: from scipy.sparse.linalg import LinearOperator, gmres

In [3]: def mymatvec(v):
   ...:     a = np.array([[4,2,1],[2,2,1],[1,1,1]])
   ...:     return a.dot(v)
   ...: 

In [4]: A = LinearOperator((3,3), mymatvec, dtype='float64')

In [5]: b = np.array([1,2,3])

In [6]: gmres(A, b)
Out[6]: (array([-0.5, -0.5,  4. ]), 0)