1

Given a NxMxM array containing N, MxM square arrays, how do I calculate the N exponents of the MxM arrays.

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])]

I would like to avoid for loops and use numpy manipulation.

mbauman
  • 30,958
  • 4
  • 88
  • 123
PhysicsMan
  • 71
  • 1
  • 5

1 Answers1

2

You can use a list comprehension:

exp = [expm(x) for x in U]

Since expm accepts only a single square matrix the loop over matrices will run Python. But since the matrices are anyway to be dealt with independently this shouldn't be much of an issue.

a_guest
  • 34,165
  • 12
  • 64
  • 118