As an example, let
A = np.array([[a1, a2],
[a3, a4]])
B = np.array([[b1, b2],
[b3, b4]])
C = np.array([[c1, c2],
[c3, c4]]),
let l = [A, B, C]
, and let
I = np.array([[1, 0, 1],
[0, 1, 1]]).
I want to calculate the Matrix R
R = np.array([[a1 + c1, a2 + c2],
[b3 + c3, b4 + c4]])
I.e. in general, I have a list of k
nxm
matrices stored in l
and an index matrix I
of dimensions nxk
that specifies for each row of the result R
which of the k
matrices in l
should be used in the calculation of that row of R
. Above, the first row of I
is [1, 0, 1]
and thus A
and C
are used in the calculation of the first row of R
.
Which numpy
function can I use for this?