Speed up numpy matrix inverse

I am using Numpy/Scipy to invert a 20k matrix, it's slow. I tried:

(1) M_inv = M.I

(2) Ident = np.Identity(len(M))
    M_inv = scipy.linalg.solve(M, Ident)

(3) M_inv = scipy.linglg.inv(M)

but didn't see any speedup.

Is there any other way to speed this up?

Answers


This is a big matrix, and inverting it is going to be slow. Some options:

  • Use a numpy linked against Intel MKL (e.g. the Enthought distribution, or you can compile it yourself), which should be faster than one linked against standard BLAS/ATLAS.
  • If your matrix is sufficiently sparse, use scipy.linalg.sparse. (This will probably be slower if there are only a few zeros, though.)
  • Figure out if you really need an explicit representation of the inverted matrix to do whatever it is you're trying to do with it – often you can get away without explicitly inverting it, but it's hard to tell without knowing what it is you're doing with this matrix.

Need Your Help

Clear tables with foreign keys + Propel

php mysql zend-framework propel clear

I have a mysql database with some tables in it. An example of two tables:

Blackberry Cascades SystemDialog theme

dialog qml blackberry-10 blackberry-cascades

I'm using this manual to create ok/cancel modal dialog box in my Blackberry 10 application.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.