Andrew Gurung
  • Introduction
  • Data Science
    • Natural Language Processing
      • Sentiment analysis using Twitter
    • Linear Algebra
      • Linear algebra explained in four pages
      • Vectors
        • Vector Basics
        • Vector Projection
        • Cosine Similarity
        • Vector Norms and Orthogonality
        • Linear combination and span
        • Linear independence and Basis vectors
      • Matrices
        • Matrix Arithmetic
        • Matrix Operations
        • Functions and Linear Transformations
        • Matrix types
      • Eigendecomposition, Eigenvectors and Eigenvalues
      • Principle Component Analysis (PCA)
      • Singular-Value Decomposition(SVD)
      • Linear Algebra: Deep Learning Book
    • Calculus
      • Functions, Limits, Continuity and Differentiability
      • Scalar Derivative and Partial Derivatives
      • Gradient
      • Matrix Calculus
      • Maxima and Minima using Derivatives
      • Gradient Descent and its types
    • Statistics and Probability
      • Probability Rules and Axioms
      • Types of Events
      • Frequentist vs Bayesian View
      • Random Variables
      • MLE, MAP, and Naive Bayes
      • Probability Distributions
      • P-Value and hypothesis test
    • 7 Step DS Process
      • 1: Business Requirement
      • 2: Data Acquisition
      • 3: Data Processing
        • SQL Techniques
        • Cleaning Text Data
      • 4: Data Exploration
      • 5: Modeling
      • 6: Model deployment
      • 7: Communication
    • Miscellaneous
      • LaTeX commands
  • Computer Science
    • Primer
      • Big O Notation
  • Life
    • Health
      • Minimalist Workout Routine
      • Reddit FAQ on Nootropics
      • Hiking/Biking Resources
    • Philosophy
      • Aristotle's Defense of Private Property
    • Self-improvement
      • 100 Mental Models
      • Don't break the chain
      • Cal Newport's 5 Productivity tips
      • Andrew Ng's advice on deliberate practice
      • Atomic Habits
      • Turn sound effects off in Outlook
    • Food and Travel
      • 2019 Guide to Pesticides in Produce
      • Recipe
        • Spicy Sesame Noodles
      • Travel
        • Hiking
    • Art
      • Scott Adams: 80% of the rules of good writing
      • Learn Blues Guitar
    • Tools
      • Software
        • Docker
        • Visual Studio Code
        • Terminal
        • Comparing Git Workflow
      • Life Hacks
        • DIY Deck Cleaner
  • Knowledge Vault
    • Book
      • The Almanack of Naval Ravikant
    • Media
    • Course/Training
Powered by GitBook
On this page
  • Square Matrix
  • Symmetric Matrix
  • Triangular Matrix
  • Diagonal Matrix
  • Identity Matrix
  • Orthogonal Matrix

Was this helpful?

  1. Data Science
  2. Linear Algebra
  3. Matrices

Matrix types

PreviousFunctions and Linear TransformationsNextEigendecomposition, Eigenvectors and Eigenvalues

Last updated 6 years ago

Was this helpful?

Square Matrix

A matrix where the number of rows(m) equals to the number of columns(n).

Main diagonal: The vector of values along the diagonal of the matrix from the top left to the bottom right. (a11,a22,a33)(a_{11}, a_{22}, a_{33})(a11​,a22​,a33​)

SquareMatrixoforder3;A=[a11a12a13a21a22a23a31a32a33]Square\hspace{0.1cm}Matrix\hspace{0.1cm}of\hspace{0.1cm}order\hspace{0.1cm}3;\hspace{0.1cm}A=\begin{bmatrix} a_{11} \hspace{0.2cm} a_{12} \hspace{0.2cm} a_{13} \\ a_{21} \hspace{0.2cm} a_{22}\hspace{0.2cm} a_{23} \\ a_{31} \hspace{0.2cm} a_{32}\hspace{0.2cm} a_{33} \end{bmatrix}SquareMatrixoforder3;A=​a11​a12​a13​a21​a22​a23​a31​a32​a33​​​

Symmetric Matrix

A type of square matrix where the top-right triangle is the same as the bottom-left triangle. Note: The axis of symmetry is always the main diagonal.

A=[1234521234321234321254321],A=ATA=\begin{bmatrix} 1 \hspace{0.2cm} 2 \hspace{0.2cm} 3\hspace{0.2cm}4\hspace{0.2cm}5 \\ 2\hspace{0.2cm}1\hspace{0.2cm}2\hspace{0.2cm}3\hspace{0.2cm}4 \\ 3\hspace{0.2cm}2\hspace{0.2cm}1\hspace{0.2cm}2\hspace{0.2cm}3 \\ 4\hspace{0.2cm}3\hspace{0.2cm}2\hspace{0.2cm}1\hspace{0.2cm}2 \\ 5\hspace{0.2cm}4\hspace{0.2cm}3\hspace{0.2cm}2\hspace{0.2cm}1 \end{bmatrix}, A = A^TA=​1234521234321234321254321​​,A=AT

Triangular Matrix

A type of square matrix that has values in the upper-right or lower-left triangle and filled with zeros in the rest.

UpperTriangularMatrixA=[123023003],LowerTriangularMatrixB=[100120123]Upper Triangular Matrix A=\begin{bmatrix} 1 \hspace{0.2cm} 2 \hspace{0.2cm} 3 \\ 0 \hspace{0.2cm} 2\hspace{0.2cm} 3 \\ 0 \hspace{0.2cm} 0\hspace{0.2cm} 3 \end{bmatrix}, Lower Triangular Matrix B=\begin{bmatrix} 1 \hspace{0.2cm} 0 \hspace{0.2cm} 0 \\ 1 \hspace{0.2cm} 2\hspace{0.2cm} 0 \\ 1 \hspace{0.2cm} 2\hspace{0.2cm} 3 \end{bmatrix}UpperTriangularMatrixA=​123023003​​,LowerTriangularMatrixB=​100120123​​
from numpy import array
from numpy import tril
from numpy import triu

M = array([[1, 2, 3], [1, 2, 3], [1, 2, 3]])
upper = triu(M)
lower = tril(M)
print(upper)
print(lower)
[[1 2 3]
 [0 2 3]
 [0 0 3]]
 
 [[1 0 0]
 [1 2 0]
 [1 2 3]]

Diagonal Matrix

A matrix where values outside the main diagonal have zero value; often represented as D. Note: A diagonal matrix does not have to be square.

from numpy import array
from numpy import diag
M = array([[1, 2, 3], [1, 2, 3], [1, 2, 3]])

# extract diagonal vector
d = diag(M)
print(d)

# create diagonal matrix from diagonal vector
D = diag(d)
print(D)
[1 2 3]

[[1 0 0]
 [0 2 0]
 [0 0 3]]

Identity Matrix

A square matrix that does not change a vector when multiplied; often represented as 'I' or 'In'.

from numpy import identity
I = identity(3)
print(I)
[[1. 0. 0.]
 [0. 1. 0.]
 [0. 0. 1.]]

Orthogonal Matrix

Recap: Two vectors are orthogonal when their dot product equals zero, called orthonormal.

Orthogonal matrix is a square matrix whose columns and rows are orthonormal unit vectors; i.e perpendicular and also have a length/magnitude of 1. It is often denoted as 'Q'.

from numpy import array
from numpy import dot
from numpy import identity
from numpy.linalg import inv

Q = array([[1, 0], [0, -1]])
transpose = Q.T
inverse = inv(Q)
I = identity(2)

# inverse equivalence
print(transpose)
print(inverse)

# identity equivalence
dotproduct = dot(Q,transpose)
print(dotproduct)
print(I)​
[[ 1  0]
 [ 0 -1]]
[[ 1.  0.]
 [-0. -1.]]
[[1 0]
 [0 1]]
[[1. 0.]
 [0. 1.]]
D=[100020003],D=[10000200003000040000]D=\begin{bmatrix} 1 \hspace{0.2cm} 0 \hspace{0.2cm} 0 \\ 0 \hspace{0.2cm} 2\hspace{0.2cm} 0 \\ 0 \hspace{0.2cm} 0\hspace{0.2cm} 3 \end{bmatrix}, D=\begin{bmatrix} 1 \hspace{0.2cm} 0 \hspace{0.2cm} 0 \hspace{0.2cm} 0 \\ 0 \hspace{0.2cm} 2\hspace{0.2cm} 0 \hspace{0.2cm} 0 \\ 0 \hspace{0.2cm} 0\hspace{0.2cm} 3 \hspace{0.2cm} 0 \\ 0 \hspace{0.2cm} 0\hspace{0.2cm} 0 \hspace{0.2cm} 4 \\ 0 \hspace{0.2cm} 0\hspace{0.2cm} 0 \hspace{0.2cm} 0 \end{bmatrix}D=​100020003​​,D=​10000200003000040000​​
I=[100010001]I=\begin{bmatrix} 1 \hspace{0.2cm} 0 \hspace{0.2cm} 0 \\ 0 \hspace{0.2cm} 1\hspace{0.2cm} 0 \\ 0 \hspace{0.2cm} 0\hspace{0.2cm} 1 \end{bmatrix}I=​100010001​​
QT.Q=Q.QT=IwhereQT:TransposeofQQT=Q−1whereQ−1:InverseofQQ^T . Q = Q . Q^T = I \hspace{0.5cm}where\hspace{0.1cm}Q^T:Transpose \hspace{0.1cm}of\hspace{0.1cm} Q \newline Q^T = Q^{-1}\hspace{0.5cm}where\hspace{0.1cm}Q^{-1}:Inverse\hspace{0.1cm}of\hspace{0.1cm} QQT.Q=Q.QT=IwhereQT:TransposeofQQT=Q−1whereQ−1:InverseofQ

Link: -

Introduction to Matrix Types in Linear Algebra for Machine Learning