orthogonalize#

detkit.orthogonalize(A)#

Orthogonalize the columns of matrix.

Parameters:
Aarray_like

Input matrix. This matrix will be overwritten in place of the output orthogonal matrix.

Notes

The Gram-Schmidt method is used to orthogonalize the columns of the input matrix \(\mathbf{X}\) so that it satisfies

\[\mathbf{X}^{\intercal} \mathbf{X} = \mathbf{I},\]

where \(\mathbf{I}\) is the identity matrix.

Warning

The input matrix will be overwritten inplace.

Examples

>>> # Create a random matrix
>>> import numpy
>>> numpy.random.seed(0)
>>> A = numpy.random.rand(6, 3)

>>> # Check orthogonality of A
>>> numpy.around(A.T @ A, decimals=3)
array([[1.267, 1.845, 1.42 ],
       [1.845, 2.97 , 2.065],
       [1.42 , 2.065, 2.687]])

>>> # Orthogonalize matrix
>>> from detkit import orthogonalize
>>> orthogonalize(A)

>>> # Check orthogonality of A again
>>> numpy.around(A.T @ A, decimals=15)
array([[ 1., -0., -0.],
       [-0.,  1.,  0.],
       [-0.,  0.,  1.]])