What is Linear Algebra? #
Linear Algebra is a branch of mathematics that deals with vectors, matrices, and their operations. It is widely used in Data Science and Machine Learning.
Vectors #
A vector is a list of numbers representing magnitude and direction.
Example: #
v = [2, 4, 6]
Vector Operations #
Addition:
[1, 2] + [3, 4] = [4, 6]
Scalar Multiplication:
2 × [1, 2] = [2, 4]
Matrices #
A matrix is a 2D array of numbers (rows & columns).
Example: #
A = [[1, 2],
[3, 4]]Matrix Operations #
1. Addition #
(Add corresponding elements)
A + B = [[1+5, 2+6],
[3+7, 4+8]]Multiplication
A × B = [[(1×5 + 2×7), (1×6 + 2×8)],
[(3×5 + 4×7), (3×6 + 4×8)]]Transpose #
(Convert rows into columns)
Aᵀ = [[1, 3],
[2, 4]]Basic Python Example
import numpy as np
# Vectors
v1 = np.array([1, 2])
v2 = np.array([3, 4])
print("Addition:", v1 + v2)
print("Scalar:", 2 * v1)
# Matrices
A = np.array([[1, 2], [3, 4]])
B = np.array([[5, 6], [7, 8]])
print("Matrix Add:\n", A + B)
print("Matrix Multiply:\n", A.dot(B))
print("Transpose:\n", A.T)Importance in Data Science #
- Used in machine learning algorithms
- Helps in handling large datasets
- Important for deep learning and AI
| Concept | Definition | Example |
|---|---|---|
| Vector | 1D list of numbers | [1, 2, 3] |
| Matrix | 2D array (rows & columns) | [[1,2],[3,4]] |
| Vector Addition | Add elements | [1,2] + [3,4] = [4,6] |
| Scalar Multiplication | Multiply by number | 2 × [1,2] = [2,4] |
| Matrix Addition | Add matrices element-wise | A + B |
| Matrix Multiplication | Row × Column rule | A × B |
| Transpose | Swap rows & columns | Aᵀ |
