Skip to main content
Albero Academy

Linear Algebra

Matrix products, solving systems, and the decompositions behind ML.

Numerical Computing11 min

Linear algebra is the language of machine learning and graphics — a regression fit, a neural-network layer and a PCA are all matrix operations. NumPy's @ operator and np.linalg module give you the full toolkit.

Matrix products

The @ operator is matrix multiplication — not element-wise. Inner dimensions must match:

@ vs *
A = np.array([[1, 2], [3, 4]])
B = np.array([[5, 6], [7, 8]])
A @ B # matrix product (rows · columns)
A * B # element-wise (a different result!)
v = np.array([1, 0])
A @ v # matrix–vector product → [1 3]

Solving systems

Ax = b
A = np.array([[3, 1], [1, 2]])
b = np.array([9, 8])
x = np.linalg.solve(A, b) # [2. 3.]

Properties & decompositions

np.linalg
np.linalg.det(A) # determinant (0 → singular)
np.linalg.inv(A) # inverse
np.linalg.eig(A) # eigenvalues & eigenvectors
np.linalg.svd(A) # singular value decomposition (powers PCA)

Key takeaways

  1. 01@ (or np.dot) is matrix multiplication — not element-wise; inner dimensions must match.
  2. 02Solve Ax = b with np.linalg.solve, not by inverting A — faster and more stable.
  3. 03np.linalg provides det, inv, eig and svd.
  4. 04The SVD underlies PCA and dimensionality reduction.

Finished this chapter?

Mark it complete to track your progress through NumPy.