Diagonalizing a matrix
In linear algebra, a square matrix A is diagonalizable if it is similar to a diagonal matrix, that is, if there exists an invertible matrix P such that P−1AP is a diagonal matrix.
Diagonalizable matrices and maps are of interest because diagonal matrices are especially easy to handle. If their eigenvalues and eigenvectors are known, one can raise a diagonal matrix to a power by simply raising the diagonal entries to that same power, and the determinant of a diagonal matrix is simply the product of all diagonal entries.
How to do it…
Before getting into the details of checking whether a matrix is diagonalizable or not, let us see how to convert any 1D array into a diagonal matrix.
- Import the relevant packages:
import numpy as np
- Initialize a 1D matrix:
a= np.array([1,2,3])
- Diagonalize the matrix:
np.diag(a)
- The output of the preceding code is:
array([[1, 0, 0], [0, 2, 0], [0, 0, 3]])
You should note that all the elements within the one-dimensional array form the...