NumPy Linear AlgebraNumpy provides the following functions to perform the different algebraic calculations on the input data.
numpy.dot() functionThis function is used to return the dot product of the two matrices. It is similar to the matrix multiplication. Consider the following example. ExampleOutput: [[3400 6200] [ 374 712]] The dot product is calculated as: [100 * 10 + 200 * 12, 100 * 20 + 200 * 21] [23*10+12*12, 23*20 + 12*21] numpy.vdot() functionThis function is used to calculate the dot product of two vectors. It can be defined as the sum of the product of corresponding elements of multi-dimensional arrays. Consider the following example. ExampleOutput: 5528 np.vdot(a,b) = 100 *10 + 200 * 20 + 23 * 12 + 12 * 21 = 5528 numpy.inner() functionThis function returns the sum of the product of inner elements of the one-dimensional array. For n-dimensional arrays, it returns the sum of the product of elements over the last axis. Consider the following example. ExampleOutput: 130 numpy.matmul() functionIt is used to return the multiplication of the two matrices. It gives an error if the shape of both matrices is not aligned for multiplication. Consider the following example. Examplenumpy determinantThe determinant of the matrix can be calculated using the diagonal elements. The determinant of following 2 X 2 matrix A B can be calculated as AD - BC. The numpy.linalg.det() function is used to calculate the determinant of the matrix. Consider the following example. ExampleOutput: -2.0000000000000004 numpy.linalg.solve() functionThis function is used to solve a quadratic equation where values can be given in the form of the matrix. The following linear equations can be represented by using three matrices as: The two matrices can be passed into the numpy.solve() function given as follows. ExampleOutput: [[1. 0.] [0. 1.]] numpy.linalg.inv() functionThis function is used to calculate the multiplicative inverse of the input matrix. Consider the following example. ExampleOutput: Original array: [[1 2] [3 4]] Inverse: [[-2. 1. ] [ 1.5 -0.5]] Next TopicMatrix Multiplication |