开发者

How do I do matrix computations in python without rounding?

开发者 https://www.devze.com 2023-04-13 04:56 出处:网络
I have some integer matrices of moderate size (a few hundred rows). I need to solve equations of the form Ax = b where b is a standard basis vector and A is one of my matrices. I have been 开发者_Stac

I have some integer matrices of moderate size (a few hundred rows). I need to solve equations of the form Ax = b where b is a standard basis vector and A is one of my matrices. I have been 开发者_StackOverflow中文版using numpy.linalg.lstsq for this purpose, but the rounding errors end up being too significant.

How can I carry out an exact symbolic computation?

(PS I don't really need the code to be efficient; I'm more concerned about ease of coding.)


If your only option is to use free tools written in python, sympy might work, but it could well be simpler to use mathematica.


Note that if you're serious about your comment that you require your solution vector to be integer, then you're looking for something called the "integer least squares problem". Which is believed to be NP-hard. There are some heuristic solvers, but it all gets very complicated.


The mpmath library has support for arbitrary-precision floating-point numbers, and supports matrix algebra: http://mpmath.googlecode.com/svn/tags/0.17/doc/build/matrices.html

Using sympy to do the computation exactly is then a second option.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号