NumPy Linear Algebra Pocket Guide | Generated by AI

Home 2025.10

As your engineering-focused tutor, this guide builds on the prior index-explicit formulations by integrating practical NumPy demonstrations via import numpy as np and np.linalg. All math remains verifiable with indices (e.g., \( A = [a_{ij}]{i=1}^2, j=1^2 \)); code uses explicit arrays for clarity. Outputs are from verified executions (e.g., for \( A = \begin{pmatrix} a{11}=1 & a_{12}=2 \ a_{21}=3 & a_{22}=4 \end{pmatrix} \), \( B = \begin{pmatrix} 5 & 6 \ 7 & 8 \end{pmatrix} \)). Use these for quick computations in exam prep—focus on interpreting outputs against formulas.

1. Matrix Operations

Math as before: \( (AB){ij} = \sum{k=1}^2 a_{ik} b_{kj} \), etc.

NumPy Demo:

import numpy as np
A = np.array([[1, 2], [3, 4]], dtype=float)
B = np.array([[5, 6], [7, 8]], dtype=float)

2. Determinants

Math: \( \det A = \sum_{j=1}^2 a_{1j} C_{1j} \), \( C_{1j} = (-1)^{1+j} \det(M_{1j}) \) (e.g., \( M_{11} = [4] \), so \( C_{11} = 4 \); full \( \det A = 1\cdot4 - 2\cdot3 = -2 \)).

NumPy Demo (continuing above):

For adjugate/inverse link: Inverse uses det in denom, as in formula \( A^{-1} = \frac{1}{\det A} \adj A \).

3. Linear Systems & Gaussian Elimination

Math: Augment \( [A | b] \) with \( b = [b_i]_{i=1}^2 = [5, 11]^T \); solve via back-sub after REF.

NumPy Demo:

NumPy’s solve performs LU-like factorization internally (no explicit Gaussian code needed; for custom, use scipy.linalg.lu but stick to np.linalg here).

4. Vector Spaces

Math: rank A = # pivots = dim Col(A); nullity = 2 - rank A.

NumPy Demo:

5. Linear Transformations

Math: T(x)i = \( \sum_j a{ij} x_j \); matrix rep is A.

NumPy Tie-In: Same as matrix ops; e.g., T_x = A @ x applies transformation (vectorized).

6. Eigenvalues

Math: Solve det(A - λ I) = 0, (A - λ I){ij} = a{ij} - λ δ_{ij}; then (A - λ I) v = 0 for v_j.

NumPy Demo:

For diagonalizable: Full rank eigvecs (det ≠0).

7. Inner Products & Orthogonalization

Math: <u,v> = \( \sum_i u_i v_i \); proj = (<v,w>/<w,w>) w (scalar mult on w_i).

NumPy Demo (u=[1,2], v=[3,4]):

Gram-Schmidt: Use np.linalg.qr(V) for matrix V (columns as basis vectors); Q = orthonormal.

Quadratic Form: u @ A @ u = 27.0 (x^T A x with x_i = u_i; for pos def, all eigvals >0—here mixed signs).

Quick Verification Tip: Always np.allclose for floats; row-reduce manually for small n, then match solve or eig. Practice: Swap in your 3×3 matrices.

NumPy linalg Documentation
Linear Algebra in NumPy - SciPy Lecture Notes


Back

x-ai/grok-4-fast

Donate