Linear Algebra in NumPy:

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.

Linear Algebra in NumPy Python for Data Science - PST Analytics

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.

Linear Algebra in NumPy Python for Data Science - PST Analytics

numpy.linalg.eig(a): It is a function for computing eigen values and right eigen vectors of a square array.

Linear Algebra in NumPy Python for Data Science - PST Analytics

Linear Algebra in NumPy Python for Data Science - PST Analytics

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.

Code1:

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.

OUTPUT:

Linear Algebra in NumPy Python for Data Science - PST Analytics

Special functions:

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.

So, to learn more about algebra in python for data science, you can check this and this as well.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.