MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / is_hermitian

Function is_hermitian

linear_algebra/src/rayleigh_quotient.py:10–27  ·  view source on GitHub ↗

Checks if a matrix is Hermitian. >>> import numpy as np >>> A = np.array([ ... [2, 2+1j, 4], ... [2-1j, 3, 1j], ... [4, -1j, 1]]) >>> is_hermitian(A) True >>> A = np.array([ ... [2, 2+1j, 4+1j], ... [2-1j, 3, 1j], ... [4, -1j, 1]])

(matrix: np.ndarray)

Source from the content-addressed store, hash-verified

8
9
10def is_hermitian(matrix: np.ndarray) -> bool:
11 """
12 Checks if a matrix is Hermitian.
13 >>> import numpy as np
14 >>> A = np.array([
15 ... [2, 2+1j, 4],
16 ... [2-1j, 3, 1j],
17 ... [4, -1j, 1]])
18 >>> is_hermitian(A)
19 True
20 >>> A = np.array([
21 ... [2, 2+1j, 4+1j],
22 ... [2-1j, 3, 1j],
23 ... [4, -1j, 1]])
24 >>> is_hermitian(A)
25 False
26 """
27 return np.array_equal(matrix, matrix.conjugate().T)
28
29
30def rayleigh_quotient(a: np.ndarray, v: np.ndarray) -> Any:

Callers 1

testsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected