Python Forum

Full Version: Getting a desired vector from lsqr in python when solving a linear system
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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 scipy.sparse.linalg, too. Thank you!