Mathematica Asked on April 25, 2021
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.
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.
Answered by yarchik on April 25, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP