使用 numpy 的 3D 数组的指数
Exponent of 3D array with numpy
给定一个包含 N 个 MxM 方阵的 NxMxM 数组,我如何计算 MxM 数组的 N 个指数。
from scipy.linalg import expm
U = np.random.rand(10,6,6) #Given 10 six by six arrays calculate the following:
exp = expm(U)
>>> [expm(U[0]),expm(U[1])...expm(U[9])]
我想避免 for 循环并使用 numpy 操作。
您可以使用列表理解:
exp = [expm(x) for x in U]
由于 expm
仅接受单个方阵,因此矩阵循环将 运行 Python。但是由于矩阵无论如何都是独立处理的,所以这应该不是什么大问题。
给定一个包含 N 个 MxM 方阵的 NxMxM 数组,我如何计算 MxM 数组的 N 个指数。
from scipy.linalg import expm
U = np.random.rand(10,6,6) #Given 10 six by six arrays calculate the following:
exp = expm(U)
>>> [expm(U[0]),expm(U[1])...expm(U[9])]
我想避免 for 循环并使用 numpy 操作。
您可以使用列表理解:
exp = [expm(x) for x in U]
由于 expm
仅接受单个方阵,因此矩阵循环将 运行 Python。但是由于矩阵无论如何都是独立处理的,所以这应该不是什么大问题。