3
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ This post and the other answers should be what you are looking for. $\endgroup$
    – ala10
    Commented Dec 12, 2020 at 15:03
  • $\begingroup$ I suggest TensorProduct-TensorContract combo, and don't forget the metric tensors used to lower/lift indices. $\endgroup$ Commented Dec 13, 2020 at 3:24

1 Answer 1

4
$\begingroup$

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.

$\endgroup$

Your Answer

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

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