ishermitian#
- scipy.linalg.ishermitian(a, atol=None, rtol=None)#
Check if a square 2D array is Hermitian.
The documentation is written assuming array arguments are of specified “core” shapes. However, array argument(s) of this function may have additional “batch” dimensions prepended to the core shape. In this case, the array is treated as a batch of lower-dimensional slices; see Batched Linear Operations for details.
- Parameters:
- andarray
Input array of size (N, N)
- atolfloat, optional
Absolute error bound
- rtolfloat, optional
Relative error bound
- Returns:
- herbool
Returns True if the array Hermitian.
- Raises:
- TypeError
If the dtype of the array is not supported, in particular, NumPy float16, float128 and complex256 dtypes.
See also
issymmetricCheck if a square 2D array is symmetric
Notes
For square empty arrays the result is returned True by convention.
numpy.infwill be treated as a number, that is to say[[1, inf], [inf, 2]]will returnTrue. On the other handnumpy.nanis never symmetric, say,[[1, nan], [nan, 2]]will returnFalse.When
atoland/orrtolare set to , then the comparison is performed bynumpy.allcloseand the tolerance values are passed to it. Otherwise an exact comparison against zero is performed by internal functions. Hence performance can improve or degrade depending on the size and dtype of the array. If one ofatolorrtolgiven the other one is automatically set to zero.Examples
>>> import numpy as np >>> from scipy.linalg import ishermitian >>> A = np.arange(9).reshape(3, 3) >>> A = A + A.T >>> ishermitian(A) True >>> A = np.array([[1., 2. + 3.j], [2. - 3.j, 4.]]) >>> ishermitian(A) True >>> Ac = np.array([[1. + 1.j, 3.j], [3.j, 2.]]) >>> ishermitian(Ac) # not Hermitian but symmetric False >>> Af = np.array([[0, 1 + 1j], [1 - (1+1e-12)*1j, 0]]) >>> ishermitian(Af) False >>> ishermitian(Af, atol=5e-11) # almost hermitian with atol True