Author Topic: Inverse Matrix (Numpy) int too large to convert to float  (Read 2173 times)

0 Members and 1 Guest are viewing this topic.

Piman9

• LV0 Newcomer (Next: 5)
• Posts: 3
• Rating: +0/-0
Inverse Matrix (Numpy) int too large to convert to float
« on: April 25, 2015, 05:48:55 pm »

I am trying to take the inverse of a 365x365 matrix. Some of the values get as large as 365**365 and so they are converted to long numbers. I don't know if the linalg.matrix_power() function can handle long numbers. I know the problem comes from this (because of the error message and because my program works just fine for smaller matrices) but I am not sure if there is a way around this. The code needs to work for a NxN matrix. Here's my code:
Code: [Select]
item=0for i in xlist:    xtotal.append(arrayit.arrayit(xlist[item],len(xlist)))    item=item+1print xtotalxinverted=numpy.linalg.matrix_power(xtotal,-1)coeff=numpy.dot(xinverted,ylist)arrayit.arrayit:
Code: [Select]
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 is taking x,y coordinates from a list (list of x's and list of y's) and makes a function. Thanks!

Piman9

• LV0 Newcomer (Next: 5)
• Posts: 3
• Rating: +0/-0
Re: Inverse Matrix (Numpy) int too large to convert to float
« Reply #1 on: May 05, 2015, 01:11:50 pm »
Maybe distributing a constant across the matrix? Help?

harold

• Posts: 226
• Rating: +41/-3
Re: Inverse Matrix (Numpy) int too large to convert to float
« Reply #2 on: May 05, 2015, 01:15:09 pm »
Can't you avoid taking the inverse? It's usually not necessary, most of the time you can use basic linear algebra to rewrite it in terms of "taking an RREF of an augmented matrix", things like that. Obviously it depends on what you're doing with it though.
Check the haroldbot thread for the supported commands and syntax.
You can use haroldbot from this website.

Piman9

• LV0 Newcomer (Next: 5)
• Posts: 3
• Rating: +0/-0
Re: Inverse Matrix (Numpy) int too large to convert to float
« Reply #3 on: May 05, 2015, 01:22:38 pm »
I'm using the inverse matrix to solve a 365 variable system of equations.  The cells do follow a sort of patter but the pattern is long. I'm not exactly sure what you mean.