Skip to main content

Posts

Showing posts with the label sparse matrix

Matrices and Matrix Arithmetic

Matrices and Matrix Arithmetic Matrices are a foundational element of linear algebra. Matrices are used throughout the fi eld 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("Matrix A") print(A) # define second matrix B = array([[1, 2, 3],[4, 5, 6]]) print("Matrix B") print(B) # add matrices C = A + B print("Matrix C") print(C) o/p: Matrix A [[1