57.Numpy-Matrix and Matrix operations
Matrices and Matrix Arithmetic Matrices are a foundational element of linear algebra. Matrices are used throughout the field of machine learning in the description of algorithms and processes such as the input data variable (X) when training an algorithm.A matrix is a two-dimensional array of scalars with one or more columns and one or more rows. Defining a Matrix We can represent a matrix in Python using a two-dimensional NumPy array. A NumPy array can be constructed given a list of lists. For example, below is a 2 row, 3 column matrix. # create matrix from numpy import array A = array([[1, 2, 3], [4, 5, 6]]) print(A) o/p: [[1 2 3] [4 5 6]] Matrix Addition # matrix addition from numpy import array # define first matrix A = array([[1, 2, 3],[4, 5, 6]]) print(A) # define second matrix B = array([[1, 2, 3],[4, 5, 6]]) print(B) # add matrices C = A + B # or np.add(A,b) print(C) o/p: [[1 2 3] [4 5 6]] [[1 2 3] [4 5 6]] [[ 2 4 6] [ 8 10 12]] Matrix Subtraction # matrix subtraction fro