添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
numpy.linalg library is used  calculates the determinant of the input matrix, rank of the matrix, Eigenvalues and Eigenvectors of the matrix

  1. Determinant Calculation

np.linalg.det is used to find the determinant of matrix.

>>> import numpy as np

>>> matrix = np.array ( [ [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] )

>>> print ( ” Matrix is : \n “, matrix)

Matrix is :

[[ 4  5  6]

[ 7  8  9]

[10 11 12]]

>>> print ( ” Determinant of the matrix : \n “, np.linalg.det ( matrix ) )

Determinant of the matrix :

3.197442310920453e-15

The rank of a matrix rows (columns) is the maximum number of linearly independent rows (columns) of this matrix, that is count of number of non-zero rows. np.linalg.rank is used to find the rank of the matrix.

>>> import numpy as np

>>> matrix = np.array ( [ [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] )

>>> print ( ” Matrix is : \n “, matrix)

Matrix is :

[[ 4  5  6]

[ 7  8  9]

[10 11 12]]

>>> print ( ” Rank of the matrix : \n “, np.linalg.matrix_rank ( matrix ) )

Rank of the matrix :

Eigenvectors are widely used in Machine Learning image processing. Eigenvectors are vectors that when that transformation is applied, change only in scale (not direction). np.linalg.eig() is used to find the eigen values and eigen vectors of the matrix.

>>> import numpy as

>>> matrix = np.array ( [ [ 4, 5, 6 ], [ 7, 8, 9 ], [ 10, 11, 12 ] ] )

>>> print ( ” Matrix is : \n “, matrix)

Matrix is :

5  6]

8  9]

[10 11 12]]

>>> eigenvalues , eigenvectors = np.linalg.eig ( matrix )

>>> print(” eigenvalues are : \n”, eigenvalues )

eigenvalues are :

[ 2.47279221e+01 -7.27922061e-01  1.52670994e-15]

>>> print (” eigenvectors are : \n”, eigenvectors )

eigenvectors are :

[[-0.35200306 -0.76057531  0.40824829]

[-0.55343002 -0.05691242 -0.81649658]

[-0.75485698  0.64675048  0.40824829]]