Python Save (sparse) matrix with variable inside

I have several matrices of decent size (2000 * 2000), and I want to have symbolic expressions in the elements of the matrices, i.e. .9**b + .8**b + .7**b ... is an example of an element. Matrices are quite rare.

I create these matrices by adding intermediate calculations. I would like to save them to disk so that I can read them later and evaluate them with different b values.

I played with sympy and it does exactly what I need, but do it slowly to make simple additions. From what I read, it seems that anano or tensor flow can do this with tensors, but I could not figure out how to put the symbol in the tensor.

Can someone point me in the right direction to the best tool to use in this task? I would prefer it to be in python, but if something outside of python would do the work, which would be good too.

+6
source share
1 answer

The problem is most likely due to the fact that you accept symbolic power. But for some reason, SymPy is trying to find an explicit form for symbolic power. For instance:

 In [12]: x = Symbol('x') In [13]: print(Matrix([[1, 2], [3, 4]])**x) Matrix([[-2*(5/2 + sqrt(33)/2)**x*(-2/((-3/2 + sqrt(33)/2)*(-1/2 + sqrt(33)/6)**2*(sqrt(33)/4 + 11/4)) + 1/(-1/2 + sqrt(33)/6))/(-sqrt(33)/2 - 3/2) + 2*(-sqrt(33)/2 + 5/2)**x/((-3/2 + sqrt(33)/2)*(-1/2 + sqrt(33)/6)*(sqrt(33)/4 + 11/4)), -4*(5/2 + sqrt(33)/2)**x/((-3/2 + sqrt(33)/2)*(-1/2 + sqrt(33)/6)*(-sqrt(33)/2 - 3/2)*(sqrt(33)/4 + 11/4)) - 2*(-sqrt(33)/2 + 5/2)**x/((-3/2 + sqrt(33)/2)*(sqrt(33)/4 + 11/4))], [(5/2 + sqrt(33)/2)**x*(-2/((-3/2 + sqrt(33)/2)*(-1/2 + sqrt(33)/6)**2*(sqrt(33)/4 + 11/4)) + 1/(-1/2 + sqrt(33)/6)) - (-sqrt(33)/2 + 5/2)**x/((-1/2 + sqrt(33)/6)*(sqrt(33)/4 + 11/4)), 2*(5/2 + sqrt(33)/2)**x/((-3/2 + sqrt(33)/2)*(-1/2 + sqrt(33)/6)*(sqrt(33)/4 + 11/4)) + (-sqrt(33)/2 + 5/2)**x/(sqrt(33)/4 + 11/4)]]) 

Is this really what you want to do? Do you know the value of b ahead of time? You can leave the expression MatPow(arr, b) as an energy source with MatPow(arr, b) .

0
source

All Articles