The calculation handled here is when you want to combine various combinations. Other than that, please refer to other articles.
\boldsymbol A = \left(a_0, \dots, a_I \right) \\
\boldsymbol B = \left(b_0, \dots, b_J \right) \\
\boldsymbol C = \left(c_0, \dots, c_K \right) \\
From
a_i b_j c_k
If you want to calculate
A = np.arange(2)+1
B = np.arange(3)+1
C = np.arange(4)+1
print("A=", A)
print("B=", B)
print("C=", C)
D = A[:, np.newaxis, np.newaxis] * B[:, np.newaxis] * C
print("\nD=", D)
print("\nD.shape=", D.shape)
A= [1 2]
B= [1 2 3]
C= [1 2 3 4]
D= [[[ 1 2 3 4]
[ 2 4 6 8]
[ 3 6 9 12]]
[[ 2 4 6 8]
[ 4 8 12 16]
[ 6 12 18 24]]]
D.shape= (2, 3, 4)
If you only have $ b_j c_k $, numpy.outer
is enough.
print(np.outer(B,C))
print(B[:, np.newaxis] * C)
[[ 1 2 3 4]
[ 2 4 6 8]
[ 3 6 9 12]]
[[ 1 2 3 4]
[ 2 4 6 8]
[ 3 6 9 12]]
\boldsymbol A = \left(a_0, \dots, a_I \right) \\
\boldsymbol B = \left(b_0, \dots, b_J \right) \\
\boldsymbol C = \left(c_0, \dots, c_K \right) \\
\\
\boldsymbol X = \left(x_0, \dots, x_L \right) \\
\boldsymbol Y = \left(y_0, \dots, y_J \right) \\
\boldsymbol Z = \left(z_0, \dots, z_K \right) \\
\\
a_i x_l \sum_{j=0}^J b_j y_j \sum_{k=0}^K c_k z_k \\
\newcommand{\argmax}{\mathop{\rm arg~max}\limits}
\newcommand{\argmin}{\mathop{\rm arg~min}\limits}
\argmax_{j}{a_i x_l b_j y_j \sum_{k=0}^K c_k z_k} \\
in the case of
ABC = A[:, np.newaxis, np.newaxis] * B[:, np.newaxis] * C
XYZ = X[:, np.newaxis, np.newaxis] * Y[:, np.newaxis] * Z
print("\nABC=", ABC)
print("\nXYZ=", XYZ)
O = ABC[:, np.newaxis] * XYZ
P = np.sum(O, axis=(2,3))
Q = np.argmax(np.sum(O, axis=3), axis=2)
print("O=", O)
print("P=", P)
print("Q=", Q)
I think I should do it.
Recommended Posts