def expm_frechet_kronform(A, method=None, check_finite=True):
 if check_finite:
  A = np.asarray_chkfinite(A)
 else:
  A = np.asarray(A)
 if ((len(A.shape) != 2) or (A.shape[0] != A.shape[1])):
  raise ValueError('expected a square matrix')
 n = A.shape[0]
 ident = np.identity(n)
 cols = []
 for i in range(n):
  for j in range(n):
   E = np.outer(ident[i], ident[j])
   F = expm_frechet(A, E, method=method, compute_expm=False, check_finite=False)
   cols.append(vec(F))
 return np.vstack(cols).T

def expm_frechet_kronform ( A , method = None , check_finite = True ) : if check_finite : A = np . asarray_chkfinite ( A ) else : A = np . asarray ( A ) if ( ( len ( A . shape ) != 2 ) or ( A . shape [ 0 ] != A . shape [ 1 ] ) ) : raise ValueError ( 'expected a square matrix' ) n = A . shape [ 0 ] ident = np . identity ( n ) cols = [ ] for i in range ( n ) : for j in range ( n ) : E = np . outer ( ident [ i ] , ident [ j ] ) F = expm_frechet ( A , E , method = method , compute_expm = False , check_finite = False ) cols . append ( vec ( F ) ) return np . vstack ( cols ) . T
construct the kronecker form of the frechet derivative of expm .