Python Forum
Getting a desired vector from lsqr in python when solving a linear system
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting a desired vector from lsqr in python when solving a linear system
#1
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!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Lidar in python - Quaternions, Angular Velocity, Linear Accelleration? jttolleson 2 546 Nov-27-2023, 02:05 AM
Last Post: jttolleson
  Json filter is not capturing desired key/element mrapple2020 1 1,142 Nov-24-2022, 09:22 AM
Last Post: ibreeden
  SOlving LInear Equations in Python(Symoy, NUmpy) - Coefficient Problem quest 3 1,753 Jan-30-2022, 10:53 PM
Last Post: quest
  how can I display only desired items? 3lnyn0 5 2,051 Dec-25-2021, 06:49 PM
Last Post: menator01
Question How to understand the vector/direction mason321 0 1,118 Dec-14-2021, 10:57 PM
Last Post: mason321
  How to find vector of a 3D plot mason321 0 1,019 Nov-13-2021, 05:05 PM
Last Post: mason321
  ERROR: importing desired module mbgamer28 0 1,688 Apr-05-2021, 07:46 PM
Last Post: mbgamer28
  Not rounding to desired decimal places? pprod 2 2,570 Mar-05-2021, 11:11 AM
Last Post: pprod
  Difference between os.system("clear") and os.system("cls") chmsrohit 7 16,655 Jan-11-2021, 06:30 PM
Last Post: ykumar34
  3D vector class with inheritance from 2D vector class buss0140 4 3,159 Dec-20-2020, 08:44 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020