Feb-21-2019, 04:19 PM
I am trying to solve a linear system which has multiple solutions. Here is part of my code:
from scipy.sparse.linalg import lsqr
solution = lsqr(M, b)[0]
Now, if the matrix M is this:
[1 1 1 1]
[0 0 0 0]
[0 0 0 0]
[0 0 0 0]
[0 0 0 0]
[0 0 0 0]
and b is this:
[1 0 0 0 0 0]
The solution given by this code is this:
[1/4 1/4 1/4 1/4]
However, for my purposes, I would like to get as the solution a vector with as many zeros as possible, so in this case, it would be this:
[1 0 0 0]
Is there any way to do this? I am fine using packages other than
from scipy.sparse.linalg import lsqr
solution = lsqr(M, b)[0]
Now, if the matrix M is this:
[1 1 1 1]
[0 0 0 0]
[0 0 0 0]
[0 0 0 0]
[0 0 0 0]
[0 0 0 0]
and b is this:
[1 0 0 0 0 0]
The solution given by this code is this:
[1/4 1/4 1/4 1/4]
However, for my purposes, I would like to get as the solution a vector with as many zeros as possible, so in this case, it would be this:
[1 0 0 0]
Is there any way to do this? I am fine using packages other than
scipy.sparse.linalg
, too. Thank you!