Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Linear Algebra: Vectors & Matrices

Lesson 10 of 37 in the free Data Science notes on Siksha Sarovar, written by Rohit Jangra.

Linear Algebra: Vectors & Matrices

Linear Algebra is the branch of mathematics dealing with vectors, matrices, and linear transformations. It is arguably the most important mathematical discipline for Data Science and Machine Learning, because datasets are fundamentally represented as matrices, and most ML algorithms operate on these matrix representations.

---

Why Linear Algebra for Data Science?

  • Every dataset (spreadsheet) is a matrix — rows are samples, columns are features.
  • Images are represented as matrices of pixel values.
  • Neural networks perform millions of matrix multiplications.
  • Dimensionality reduction techniques (PCA) rely on eigenvalues and eigenvectors.
  • Recommendation systems use matrix factorization.

---

Scalars, Vectors, and Matrices

Scalars

  • A single number.
  • Example: x = 5, temperature = 36.7
  • Represented by lowercase letters: a, b, x, y

Vectors

Definition: A vector is an ordered list (array) of numbers. It represents a point or a direction in space.

  • Row Vector: v = [1, 2, 3] (horizontal)
  • Column Vector: Written vertically.
  • Dimension: A vector with n elements is called an n-dimensional vector.

Real-World Analogy: A student's exam scores across 5 subjects can be represented as a vector: scores = [85, 92, 78, 96, 88]

Types of Vectors:

TypeDescriptionExample
Zero VectorAll elements are zero[0, 0, 0]
Unit VectorHas a magnitude of 1[1, 0, 0] in 3D space
Sparse VectorMost elements are zero[0, 0, 5, 0, 0, 3, 0] (common in NLP)

Vector Operations:

OperationFormulaExample
Addition[a₁+b₁, a₂+b₂][1,2] + [3,4] = [4,6]
Scalar Multiplicationc × [a₁, a₂]3 × [1,2] = [3,6]
Dot ProductΣ aᵢ × bᵢ[1,2] · [3,4] = 3+8 = 11
Magnitude (Norm)`v= √(Σ vᵢ²)``[3,4]= √(9+16) = 5`

Dot Product — Why It Matters: The dot product is one of the most fundamental operations in ML:

  • Similarity Measurement: Cosine similarity uses dot products to measure how similar two documents or items are.
  • Neural Networks: Every neuron computes a weighted dot product of its inputs.
  • Projections: Projecting one vector onto another uses the dot product.

---

Matrices

Definition: A matrix is a rectangular array of numbers arranged in rows and columns. An m × n matrix has m rows and n columns.

Notation: A matrix is typically denoted by an uppercase bold letter like A, B, X.

Example: A 2×3 matrix: A = [[1, 2, 3], [4, 5, 6]]

Types of Matrices:

TypeDescriptionExample
Row MatrixOnly 1 row[1, 2, 3] (1×3)
Column MatrixOnly 1 column[[1], [2], [3]] (3×1)
Square MatrixSame number of rows and columns3×3 matrix
Identity Matrix (I)Diagonal elements are 1, rest 0[[1,0],[0,1]]
Zero MatrixAll elements are 0[[0,0],[0,0]]
Diagonal MatrixNon-zero elements only on diagonal[[3,0],[0,7]]
Symmetric MatrixA = Aáµ€ (transpose equals itself)Covariance matrices
Sparse MatrixMost elements are zeroText data (TF-IDF)

Matrices in Data Science:

  • A dataset with 1000 samples and 10 features is a 1000 × 10 matrix.
  • A grayscale image of 28×28 pixels (like in MNIST) is a 28 × 28 matrix.
  • A color image is a 3D tensor (Height × Width × 3 color channels).

Transpose of a Matrix

Definition: The transpose of a matrix A (written Aáµ€) is obtained by swapping its rows and columns.

If A is an m × n matrix, then Aᵀ is an n × m matrix.

Example: A = [[1, 2, 3], [4, 5, 6]] → Aᵀ = [[1, 4], [2, 5], [3, 6]]

Use in Data Science:

  • Computing covariance matrices: Cov = (1/n) × Xáµ€ × X
  • Many ML formulas require the transpose for matrix multiplication compatibility.

Summary

  • Scalars, vectors, and matrices are the building blocks of linear algebra.
  • Vectors represent data points; matrices represent entire datasets.
  • The dot product is essential for similarity, neural networks, and projections.
  • Matrix types (Identity, Diagonal, Sparse, Symmetric) appear frequently in ML.
  • The transpose is a fundamental operation used in formulas across data science.