I have this code:
from itertools import product
from numpy import zeros
Ysys = zeros((2*n_bus, 2*n_bus))
for a, b in product(range(n_bus), range(n_bus)):
Ysys[2*a, 2*b] = Yseries[a, b].real
Ysys[2*a, 2*b+1] = -Yseries[a, b].imag
Ysys[2*a+1, 2*b] = Yseries[a, b].imag
Ysys[2*a+1, 2*b+1] = Yseries[a, b].real
Yseries
is a square sparse matrix of n_bus
by n_bus
dimensions that contains complex numbers. Essentially I want to "explode" the complex matrix into a float matrix.
My for loop is inefficient since I should know in advance which are the row, column coordinates of every data entry. Ideally a
would be an array with all the row coordinates of every entry, and b
should be an array with all the column coordinates of every entry.
My problem is that I don't understand the arrays indices
and indptr
contained in my CSR matrx Yseries
.
Regardless of all that I've said, I'd appreciate indications of how to vectorize the for loop.