I would like to compute $ r_{ii'} = \sum_{kk'} A_{ii'}^{kk'} r_{kk'} $ where all indices vary from 0 to 1 to yield a vector / matrix.
1 Answer
$\begingroup$
$\endgroup$
You can use Flatten
to reshape the matrices/arrays and .
to perform the sum.
A = RandomReal[{0, 1}, {2, 3, 4, 5}];
Dimensions[A]
r = RandomReal[{0, 1}, {4, 5}];
Dimensions[r]
s = Flatten[A, {{1}, {2}, {3, 4}}].Flatten[r];
Dimensions[s]
{2, 3, 4, 5}
{4, 5}
{2, 3}
I set all dimensions to be different in order to illustrate how the method works. You can set them to 2 as requested.
TensorProduct
-TensorContract
combo, and don't forget the metric tensors used to lower/lift indices. $\endgroup$