Suppose there is a numpy matrix of shape (3, 3, 3), so there will be three 3*3 matrices, and I want to apply a function (matrix exponential) to each of the matrices, what would be a better way to do this rather than using a for loop? Below is my way of implementing it using a for loop. Thank you
import numpy as np
from scipy.linalg import expm
X = np.random.rand(3, 3, 3)
y = np.zeros((3, 3, 3))
for i in range(y.shape[0]):
y[i] = expm(X[i])