Hello could someone please help me figure out how to use np.einsum to produce the below code's result. I have a (3,3,3) tensor and I will like to get this results which I got from using two for loops. the code I wrote to produce this output is below. I am trying to use np.einsum to produce this same result attained from using two for loops in the below code. I am not familar with using np.einsum. Ideally I will also like to sum each of the resulting rows to get nine values.
Command Line Arguments
result of code below
[1 1 1]
[2 2 2]
[1 1 1]
[2 2 2]
[4 4 4]
[2 2 2]
[1 1 1]
[2 2 2]
[1 1 1]
[1 1 1]
3
6
3
9
12
6
15
18
9
6
12
6
18
24
12
import numpy as np
bb=[]
for x in range(3):
for y in range(3):
bb.append((x,y))
a = np.array([[[1,2,1],[3,4,2],[5,6,3]],
[[1,2,1],[3,4,2],[5,6,3]],
[[1,2,1],[3,4,2],[5,6,3]]])
b = np.array([[[1,2,1],[3,4,2],[5,6,3]],
[[1,2,1],[3,4,2],[5,6,3]],
[[1,2,1],[3,4,2],[5,6,3]]])
for z in range(9):
llAI = bb[z]
aal = a[:,llAI[0],llAI[1]]
for f in range(9):
mmAI=bb[f]
aam = a[:,mmAI[0],mmAI[1]]
print(np.sum(aal*aam))