Using the linear algebra module in NumPy we can perform linear algebra on any array in python for data science. We can find:
- rank, determinant, trace, etc. of an array.
- eigen value of marices.
- matrix and vector products, matrix exponentiation.
- linear and tensor equations.
Matrix Eigenvalue functions:
numpy.linalg.eigh(a, UPLO=’L’): It is a function which returns the eigen values and eigen vectors of a complex Hermitian or real symmetric matrix. It will return two objects, one 1-D array containing eigen values of a, and a 2-D square array or matrix of corresponding eigen vector.
numpy.linalg.eig(a): It is a function for computing eigen values and right eigen vectors of a square array.
Matrix and vector products:
numpy.dot(vector_a, vector_b, out=None): It will return the dot product of the vectors a and b. It is able to handle 2-D arrays, but as they are matrix they will perform matrix operations. In case of N dimensions, it will be a sum-product over the last axis of a and the second to last of b.
numpy.vdot(vector_a, vector_b): It is a function which returns the dot product of vectors a and b. In case the first argument is complex then, first argument of complex conjugate will be there for the calculation of dot product. It is able to handle multi dimensional arrays but working on it as a flattened array.
Solving equations and inverting matices:
numpy.linalg.solve(): It helps to solve linear matrix equations or a system of linear scalar equations. It computes the ‘exact’ solution, x, of the well determined i.e. full rank, linear matrix equation ax = b.
numpy.linalg.lstsq(): It will return the least squares of solutions to a linear matrix equation.
numpy.linalg.det(): It is there for computation of determinant of an array.
numpy.trace(): It will return sum along the diagonals of the array. In case a is 2-D sum along the diagonal will be returned with the given offset. The shape of resultant array will be same as that of a with axis1, and axis2 removed.