I would like to multiply tensors R = {R_1, R_2, ..., R_M}
and X = {X_1, X_2, ..., X_M}
where R_i
and X_i
are 3×3
and 3×N_i
matrices, respectively. How can I make maximum use of NumPy functionalities during the formation of the R_i × X_i
arrays?
My MWE is the following:
import numpy as np
np.random.seed(0)
M = 5
R = [np.random.rand(3, 3) for _ in range(M)]
X = []
for i in range(M):
N_i = np.random.randint(1, 6)
X_i = np.random.rand(3, N_i)
X.append(X_i)
result = np.zeros((3, 0))
for i in range(M):
R_i = R[i]
X_i = X[i]
result = np.hstack((result, np.dot(R_i, X_i)))
print(result)
New contributor
TobiR is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.