Solving linear system over integers with numpy

Posted by A. R. S. on Stack Overflow See other posts from Stack Overflow or by A. R. S.
Published on 2012-12-16T03:01:32Z Indexed on 2012/12/16 11:05 UTC
Read the original article Hit count: 202

Filed under:
|
|

I'm trying to solve an overdetermined linear system of equations with numpy. Currently, I'm doing something like this (as a simple example):

a = np.array([[1,0], [0,1], [-1,1]])
b = np.array([1,1,0])

print np.linalg.lstsq(a,b)[0]
[ 1.  1.]

This works, but uses floats. Is there any way to solve the system over integers only? I've tried something along the lines of

print map(int, np.linalg.lstsq(a,b)[0])
[0, 1]

in order to convert the solution to an array of ints, expecting [1, 1], but clearly I'm missing something. Could anyone point me in the right direction?

© Stack Overflow or respective owner

Related posts about python

Related posts about numpy