Matrices

Concepts

  • one-dimensional array(vector)
  • two-dimensional array(matrix)
  • Dot Product

In linear algebra, a matrix is a 2-dimensional array of numbers, symbols, or expressions arranged in rows and Columns with the same length. A matrix could be reduced as a submatrix of a matrix by deleting any collection of rows and/or columns.

Example:

Matrix Operations:

  • Adding and subtracting matrices: Possible if both have the same dimension.
  • Scalar Multiplication: multiply each number in the matrix with the scalar value.
  • Matrix Multiplication: only possible if the number of rows in first matrix is the same as the number of columns in second matrix. we use Dot Product to multiply two matrices by multiplying the numbers in each row of first matrix with the numbers in each column of second matrix, and then add the products. It’s also not commutative, that is .*
  • Transpose a Matrix: To transpose a matrix, means to replace rows with columns. When you swap rows and columns, you rotate the matrix around it's diagonal.
  • Matrix Factorization: Is a mathematical model used in Content-Based Filtering in Recommender Systems.

Notes:

  • Vectors can be considered matrices with a single row.

  • Square Matrix: it is a matrix with the same number of rows and columns.

  • Diagonal Matrix: it has values on the diagonal entries, and zero on the rest of the matrix.

  • Scalar Matrices: has equal diagonal entries and zero on the rest of the matrix.

  • Identity Matrix: it has 1 on the diagonal and 0 on the rest.

  • Zero Matrix (Null Matrix): it has only zeros.

Tensors

Tensor: A generalized matrix(N-dimensional matrix), a finite table of numerical values indexed along several discrete dimensions.

  • Dimension of a tensor is the number of indices to specify one of its coefficients.
    • A 0D tensor is a scalar.
    • A 1D tensor is a vector.
    • A 2D tensor is a matrix.
    • A 3D tensor can be seen as a vector of identically sized matrix.
    • A 4D tensor can be seen as a matrix of identically sized matrices, or a
      sequence of 3d tensors.

Example:

Notes:

  • Rank: a Tensor’s Rank is the number of directions a tensor can have in a N-dimensional space.
  • A Scalar can be considered a 0-dimensional tensor(Rank of 0), vectors is a 1-dimensional tensor(Rank of 1), and matrices a 2-dimensional tensor(Rank of 2). however when talking about tensors, it’s assumed that it’s rank is higher than 2.

Matrix Multiplication in Python