Thank you for the simplified code. Removing instances of PgenT worked.
cost_genvar, sum(
Pgen[i, j] * cov[i, k] * Pgen[k, j]
for i in bus_key for j in scenarios for k in bus_key
)
Here, the above product will simply square all the terms of the matrix Pgen. How to achieve the following
transpose (Pgen)*cov*Pgen