python - Inverse Matrix (Numpy) int too large to convert to float -


i trying take inverse of 365x365 matrix. of values large 365**365 , converted long numbers. don't know if linalg.matrix_power() function can handle long numbers. know problem comes (because of error message , because program works fine smaller matrices) not sure if there way around this. code needs work nxn matrix.

here's code:

item=0 in xlist:     xtotal.append(arrayit.arrayit(xlist[item],len(xlist)))     item=item+1 print xtotal xinverted=numpy.linalg.matrix_power(xtotal,-1) coeff=numpy.dot(xinverted,ylist) 

arrayit.arrayit:

def arrayit(number, length):     newarray=[]     import decimal     i=0     while i!=(length):         newarray.insert(0,decimal.decimal(number**i))         i=i+1     return newarray; 

the program taking x,y coordinates list (list of x's , list of y's) , makes function. thanks!

one thing might try library mpmath, can simple matrix algebra , other such problems on arbitrary precision numbers.

a couple of caveats: slower using numpy, and, lutzl points out in his answer question, problem may not mathematically defined. also, need decide on precision want before start.

some brief example code,

from mpmath import mp, matrix  # set precision - see http://mpmath.org/doc/current/basics.html#setting-the-precision mp.prec = 5000 # set big @ cost of speed.    # ideally you'd precalculate need.    # quick trial 100*100 showed 5000 works , 500 fails  # see documentation @ http://mpmath.org/doc/current/matrices.html # xtotal output arrayit my_matrix = matrix(xtotal) # think should work. if not you'll have create , copy  # inverse xinverted = my_matrix**-1 coeff = xinverted*matrix(ylist) # note lutlz pointed out want use solve instead of calculating inverse.  # think mpmath import lu_solve coeff = lu_solve(my_matrix,matrix(ylist)) 

i suspect real problem maths rather software, doubt work fantastically you, it's possible!


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -