Optimization Kronecker product for sparse matrices

89 Views Asked by At

I am doing this operation with numpy to get the tensor product of the T matrix (15 times):

import numpy as np

T_gate = np.array([[1,0],[0,np.exp(1j*np.pi/4)]])

T = 1
for i in range(15):
    T = np.kron(T,T_gate)

Of course this is very slow, also because T is complex, so every value of the final matrix is allocated as a complex variable (even if they have 0j).

I am looking for some way to speed up this process. Note that the final matrix will have a lot of zero elements.

I have tried to save everything in a file, but it seems slower like this, and I have also tried to remove the imaginary part when it is zero, but the nested for loop takes forever.

0

There are 0 best solutions below