nmiculinic
nmiculinic

Reputation: 2474

How to solve redundant linear systems in numpy?

Problem I'm trying to solve is as follows. I have some linear equations with redundancy -- Ax = s where A isn't squared but has more rows than columns. Any advice shall be appreciated.

Here is what I'd like to do as elegantly as possible. I have some matrix A with n rows and m columns; n >= m.

What I'd like to generate is square matrix B from A such that m rows are selected from A and B is regular matrix.

That way I'll get regular matrix and I can use numpy.linalg.solve to calculate the solution.

Upvotes: 2

Views: 789

Answers (1)

Simon Gibbons
Simon Gibbons

Reputation: 7194

You can use np.linalg.lstsq to calculate the least squares solution to your problem (i.e. you don't need to throw any data away as you are proposing in your question).

This will find the vector x which minimizes the distance | s - Ax |

Upvotes: 1

Related Questions