2
$\begingroup$

Consider the following:

I start with a $2\times 2$ matrix $W_{ij}$. I then take this $W$ matrix and make a new tensor, $T$, by doing the following: $$ T_{ijkl}=\sum_{a}W_{ai}W_{aj}W_{ak}W_{al} $$ which in my code I am using the (slick) ``einsum'' tool in numpy:

tt = np.einsum('ai, aj, ak, al', w, w, w, w)

with import numpy as np for np. Next I preform the following: $$ M_{XX'y''y'}=\sum_{y}T_{xx'yy'}T_{x''x'''y''y} $$ with $X=x\otimes x''$ and $X'=x'\otimes x'''$. Now when I do a naive reshape in numpy

mtensor = np.einsum('ikma, jlan', tt, tt).reshape(4, 4, 2, 2)

This simply unfolds the array and then recollects in order. However, I would like to have the power to combine certain indices (states) into a single index (like an outer product but for indices). That is, take my two, $2$ state indices, and combine them into a $4$ state index that is all the possible combinations of their states. If someone knows a slick way to do this in numpy I would greatly appreciate some documentation or an answer. Thanks in advance.

$\endgroup$

1 Answer 1

2
$\begingroup$

Turns out if the indices are input in the alphabetical order as they are up above, the reshape actually is the correct product of states into a single index. Sorry, for this question, I honestly didn't know it was already like this.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.