Questions tagged [matrix-inverse]

The matrix inverse, A^{-1}, is a mathematical relationship such that given a square n x n matrix A, A*A^{-1} = A^{-1}*A = I, where I is the identity matrix. Use this tag with regards to any numerical methods or computations that require the use or calculation of the matrix inverse.

Computation of the inverse of a square matrix, provided it is invertible (i.e., full-rank), is often via LU factorization. When the matrix is positive-definite, Cholesky factorization is often used. In standard numerical linear algebra library , dgesv and dpotrf respectively performs LU and Cholesky factorization.

In reality it is rare that a matrix inverse needs be explicitly formed, and matrix multiplications involving a matrix inverse is done by one of the factorizations above, and a triangular system solving.

509 questions
4
votes
1 answer

Computing pseudo-inverse of a matrix in C++

I'm looking to compute the Moore-Penrose pseudo-inverse of a matrix in C++, can someone point me to a library implementation or a numerical recipe? Thanks!
Mark Elliot
  • 75,278
  • 22
  • 140
  • 160
4
votes
1 answer

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…
Jensen
  • 1,653
  • 4
  • 26
  • 42
3
votes
1 answer

Python Sparse matrix inverse and laplacian calculation

I have two sparse matrix A (affinity matrix) and D (Diagonal matrix) with dimension 100000*100000. I have to compute the Laplacian matrix L = D^(-1/2)*A*D^(-1/2). I am using scipy CSR format for sparse matrix. I didnt find any method to find inverse…
3
votes
1 answer

Speed-up a variable-dependent matrix inverse computation in Python

I have an iterative problem where at each iteration I need to perform a series of matrix operations, which I want to speed up. The majority of the calculation involves constant variables, except for a varying one. My question is: is it possible to…
Andrea
  • 31
  • 3
3
votes
0 answers

LAPACKE or MAGMA GPU - inversion of matrix with Cholesky factorization - functions magma_dpotrf_gpu and magma_dpotri_gpu

I have a first version of a function that inverses a matrix of size m and using magma_dgetrf_gpu and magma_dgetri_gpulike this : // Inversion magma_dgetrf_gpu( m, m, d_a, m, piv, &info); magma_dgetri_gpu( m, d_a, m, piv, dwork, ldwork,…
user1773603
3
votes
0 answers

Numpy make faster inverse matrix

I have a complex 2D array (HH) of which I want to do the inverse and I only want its first term, iterated in 3 for loop, . For M, C, K (2D arrays) of reasonable size it doesn't take long, but if I increase their size the wait becomes infinite. One…
Bruce
  • 31
  • 2
3
votes
2 answers

Pytorch's Autograd does not support complex matrix inversion, does anyone have a workaround?

Somewhere in my loss function, I invert a complex matrix of size 64*64. Although complex matrix inversion is supported for torch.tensor, the gradient cannot be computed in the training loop as I get this error: RuntimeError: inverse does not support…
3
votes
0 answers

Why does plotting something with matplotlib change the first outcome of a numpy.linalg.inv inversion with complex entries and how to avoid it?

I was coding for a project of mine and found some strange nan values appearing in my code the first time I ran it, which disappeared when I ran the same line of code a second time. Searching for the reason took me some hours and I nailed it down to…
Frederix96
  • 31
  • 3
3
votes
1 answer

Numpy: Singular Matrix

I am trying to calculate the inverse of a matrix of the form X'X using NumPy as follows. df = pd.read_csv('https://raw.githubusercontent.com/jianghaochu/data/master/x.csv') X = np.array(df) X.shape # returns (92,…
JCHU
  • 33
  • 5
3
votes
0 answers

Weird numpy blocking behaviour when inverting matrix on Windows

On my windows 7 machine, this piece of code import numpy as np np.random.seed(1) import time def main(): for i in range(0, 1000): A = np.random.rand(100, 100) t = time.time() A_inv = np.linalg.inv(A) print…
JerryE
  • 31
  • 2
3
votes
1 answer

Matrix Inversion of Banded Sparse Matrix using SciPy

I am trying to solve the inverse of a banded sparse matrix in the most efficient way so that I can incorporate this in my real-time system. I am generating sparse-banded matrices which represent a convolution operation. Currently, I am using spsolve…
Maxtron
  • 272
  • 1
  • 2
  • 15
3
votes
0 answers

MATLAB Matrix Inversion: inv(X) versus X\eye(size(X))

Based on the wonderful MATLAB documentation, it is clear that when solving systems of linear equations, it is preferable to use X\b to inv(X)*b for reasons of numerical stability. It also notes that X^(-1) is equivalent to inv(X). But it makes no…
TimD1
  • 982
  • 15
  • 26
3
votes
1 answer

Inverting a matrix using the LU decomposition

I have written the following Matrix class in cython for the matrix inversion and some other linear algebra operations. I tried to use the LU decomposition, in order to compute the inverse of a matrix. The speed of code is good. I tried to implement…
Dalek
  • 4,168
  • 11
  • 48
  • 100
3
votes
1 answer

Can Spark and the ScalaNLP library Breeze be used together?

I'm developing a Scala-based extreme learning machine, in Apache Spark. My model has to be a Spark Estimator and use the Spark framework in order to fit into the machine learning pipeline. Does anyone know if Breeze can be used in tandem with Spark?…
LucieCBurgess
  • 759
  • 5
  • 12
  • 26
3
votes
1 answer

Why the matrix inversion function in numpy and scipy returns different results with big quadratic matrices?

Lets say I define a big quadratic matrix (e.g. 150x150). One time it is a numpy array (matrix A), one time it is a scipy sparse array (matrix B). import numpy as np import scipy as sp from scipy.sparse.linalg import spsolve size = 150 A =…
PiMathCLanguage
  • 363
  • 4
  • 15