4

Matlab and Julia have the backslash operator that solves linear systems. I don't really know what Matlab does, but Julia does not compute the inverse, but it computes the effect the inverse has on a given vector, which is computationally easier.

I have a numpy sparse matrix and I want to apply its pseudo-inverse to a vector. Does Python have to compute the pseudo-inverse first or is there a backslash-like operator I can use?

Edit: In a sense I want to solve a linear system Ax=b. However the matrix A does not have full rank and the vector b is not in A's range. So the system does not have a solution. So in practice I want to get the vector X that minimises the norm of Ax-b. This is exactly what the pseudo-inverse matrix does. My question is whether I there is a function that will give me that without having to compute the pseudo-inverse first.

Gloweye
  • 1,294
  • 10
  • 20
tst
  • 1,117
  • 2
  • 10
  • 21
  • 2
    [Matlab seems to have an algorithm](https://www.mathworks.com/help/matlab/ref/mldivide.html#bt4jslc-6) to decide how to solve the system. In Python, you could use [`linalg.solve`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.solve.html) or [`linalg.lstsq`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.lstsq.html), depending on your system. – dalmago Oct 31 '19 at 19:05
  • Are you looking for the function `scipy.sparse.linalg.spsolve` or `svds` ? Or asking if there's a 1-character operator to do the job? – Demi-Lune Oct 31 '19 at 20:52
  • @dalmago thank you, lstsq is exactly what I wanted. – tst Nov 01 '19 at 08:18
  • Actually it may not be what I need. What happens if A does not have full rank? – tst Nov 01 '19 at 08:55
  • scipy should have documentation on that. Or just try it and see what happens. – Gloweye Nov 01 '19 at 08:57

0 Answers0