def matrix_exponent(M):
if (M.shape[<NUM_LIT:0>] == <NUM_LIT:1>): <EOL><INDENT>Mexp = np.array( ((np.exp(M[<NUM_LIT:0>,<NUM_LIT:0>]) ,),) )<EOL><DEDENT>else: <EOL><INDENT>method = None<EOL>try:<EOL><INDENT>Mexp = linalg.expm(M)<EOL>method = <NUM_LIT:1><EOL><DEDENT>except (Exception,) as e:<EOL><INDENT>Mexp = linalg.expm3(M)<EOL>method = <NUM_LIT:2><EOL><DEDENT>finally:<EOL><INDENT>if np.any(np.isnan(Mexp)):<EOL><INDENT>if method == <NUM_LIT:2>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>Mexp = linalg.expm3(M)<EOL>method = <NUM_LIT:2><EOL>if np.any(np.isnan(Mexp)):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>return Mexp<EOL>
The function computes matrix exponent and handles some special cases