def cosm(A):
 A = _asarray_square(A)
 if np.iscomplexobj(A):
  return (0.5 * (expm((1j * A)) + expm(((-1j) * A))))
 else:
  return expm((1j * A)).real

def cosm ( A ) : A = _asarray_square ( A ) if np . iscomplexobj ( A ) : return ( 0.5 * ( expm ( ( 1j * A ) ) + expm ( ( ( - 1j ) * A ) ) ) ) else : return expm ( ( 1j * A ) ) . real
compute the matrix cosine .