Skip to main content

MATH 345: Linear Algebra and Optimization

Appendix B NumPy and SymPy Quick Reference for the Labs

This appendix explains the computational notation used in the Applications and Computation sections and linked notebooks. It assumes familiarity with basic Python variables, arithmetic, functions, and loops, but it does not assume prior experience with NumPy arrays, array slicing, matrix products, numerical linear algebra, or SymPy symbolic matrices.
The goal is not to teach all of Python. The goal is to help you read short computational snapshots as mathematical notation.
Where to look.
Arrays, shapes, and slicing
Use B.1, B.2, and B.3 when code imports libraries, creates arrays, checks shapes, or selects rows and columns.
Products and vector comparisons
Use B.4, B.5, and B.6 when code uses *, @, norms, distances, cosine similarity, or rankings.
Row-wise computations and constructors
Use B.7 and B.8 when code uses axes, sums, maxima, design matrices, or common arrays.
Numerical checks
Use B.9 when code checks approximate equality, residual orthogonality, or rounded output.
Linear algebra commands
Use B.10 for rank, determinants, solves, least squares, factorizations, eigenvalue commands, and outer products.
Symbolic computation
Use B.11 for SymPy matrices, row reduction, null spaces, Jacobians, substitution, and conversion to NumPy.
Small Python patterns
Use B.12 for helper functions, loops, comprehensions, and assertions.
Optional code
Use B.13 and B.14 for optional attention masks and plotting.