Created
February 15, 2024 10:22
-
-
Save neftlon/c0652e193bf856097152621ce9a1a3ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np, itertools, functools, operator | |
def matrix_exp(A, num_iters=100): | |
inv_facs = itertools.accumulate(range(1,num_iters+1), operator.mul, initial=1) | |
As = itertools.accumulate(range(num_iters), lambda Ap, _: np.dot(Ap, A), initial=A) | |
return sum(1. / inv_fac * A for inv_fac, A in zip(inv_facs, As)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment