pyyeti.ytools.isdiag¶
- pyyeti.ytools.isdiag(A, tol=1e-12)[source]¶
Checks contents of square matrix A to see if it is approximately diagonal.
- Parameters:
A (2d numpy array) – If not square or if number of dimensions does not equal 2, this routine returns False.
tol (scalar; optional) – The tolerance value.
- Returns:
True if A is a diagonal matrix, False otherwise.
Notes
If all off-diagonal values are less than tol times the maximum diagonal value (absolute-valuewise), this routine returns True. Otherwise, False is returned.
See also
Examples
>>> from pyyeti import ytools >>> import numpy as np >>> A = np.diag(np.arange(5.0)) >>> ytools.isdiag(A) True >>> A[0, 2] = .01 >>> A[2, 0] = .01 >>> ytools.isdiag(A) # symmetric but not diagonal False >>> ytools.isdiag(A[1:, :]) # non-square False