Skip to main content\(\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\dimens}{\operatorname{dim}}
\DeclareMathOperator{\row}{\operatorname{row}}
\DeclareMathOperator{\col}{\operatorname{col}}
\newcommand{\im}{\operatorname{im}}
\newcommand{\nulls}{\operatorname{null}}
\newcommand{\minor}{\operatorname{minor}}
\newcommand{\spans}{\operatorname{span}}
\newcommand{\nullity}{\operatorname{nullity}}
\newcommand{\kers}{\operatorname{ker}}
\newcommand{\proj}{\operatorname{proj}}
\newcommand{\diag}{\operatorname{diag}}
\newcommand{\Tr}{\operatorname{Tr}}
\newcommand{\rank}{\operatorname{rank}}
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Section B.15 Quick Reference
Array setup and shapes. See
B.1 and
B.2.
- Array
np.array([...]).
Read as. Create an array.
Used for. All labs.
- Array conversion
np.asarray(...).
Read as. Treat array-like input as an array.
Used for. Helper functions.
- Reshape
.reshape(m, n).
Read as. Rearrange entries into a new shape.
Used for. Matrix-shaped numerical output.
- Display options
np.set_printoptions(...).
Read as. Change printed display of arrays.
Used for. Readability.
- Floating-point data
dtype=float.
Read as. Request floating-point numerical data.
Used for. SymPy-to-NumPy conversion.
- Shape
A.shape.
Read as. Dimensions.
Used for. Shape checks.
Matrix products and entrywise operations. See
B.4 and
B.5.
- Transpose
A.T.
Read as. Transpose.
Used for. Residual checks and normal equations.
- Dot product
u @ v.
Read as. Dot product.
Used for. Cosine similarity.
- Matrix-vector product
A @ x.
Read as. Matrix-vector product.
Used for. Linear maps.
- Matrix product
A @ B.
Read as. Matrix product.
Used for. Composition and attention.
- Outer product
np.outer(g, h).
Read as. Rank-one outer product.
Used for. Matrix updates such as gradient steps.
- Entrywise product
u * v.
Read as. Entry-by-entry product.
Used for. Elementwise operations.
- Norm
np.linalg.norm(x).
Read as. Norm.
Used for. Distances and residuals.
- Row-wise norms
np.linalg.norm(X, axis=1).
Read as. One norm per row.
Used for. Row-wise cosine similarity.
Indexing, reductions, and entrywise functions. See
B.3,
B.6, and
B.7.
- Ranking
np.argsort(scores)[::-1].
Read as. Rank scores largest-to-smallest.
Used for. Document similarity.
- First column
A[:, 0].
Read as. All rows, first column.
Used for. Column extraction.
- Column block
A[:, :k].
Read as. All rows, first
k columns.
Used for. SVD reconstruction.
- Row block
Vt[:k, :].
Read as. First
k rows, all columns.
Used for. SVD reconstruction.
- Row sums
A.sum(axis=1).
Read as. One sum per row.
Used for. Attention normalization.
- General sum
np.sum(...).
Read as. Sum selected or all entries.
Used for. Totals and SVD energy.
- Cumulative energy
np.cumsum(s**2).
Read as. Cumulative squared singular-value totals.
Used for. SVD energy curves.
- Row maximum
np.max(..., axis=..., keepdims=True).
Read as. Maximum along an axis with shape preserved.
Used for. Stable softmax.
- Coordinatewise maximum
np.maximum(z, 0).
Read as. Entry-by-entry maximum with zero.
Used for. ReLU.
- Exponential
np.exp(x).
Read as. Entry-by-entry exponential.
Used for. Softmax.
- Logarithm
np.log(x).
Read as. Entry-by-entry logarithm.
Used for. Loss and log probabilities.
- Square root
np.sqrt(x).
Read as. Entry-by-entry square root.
Used for. Norms and scales.
- Hyperbolic tangent
np.tanh(x).
Read as. Entry-by-entry hyperbolic tangent.
Used for. Fixed hidden layer.
Constructors and linear algebra. See
B.8,
B.9, and
B.10.
- Ones vector
np.ones(n).
Read as. Vector of ones.
Used for. Test data and constant columns.
- Matching ones
np.ones_like(t).
Read as. Ones with the same shape.
Used for. Constant feature columns and masks.
- Matching constants
np.full_like(t, value).
Read as. Fill the same shape with one value.
Used for. Baseline arrays and plotting helpers.
- Zero array
np.zeros((m, n)).
Read as. Make an
\(m\times n\) zero array.
Used for. Test data and placeholders.
- Identity matrix
np.eye(n).
Read as. Make an
\(n\times n\) identity matrix.
Used for. Rank and inverse checks.
- Column stack
np.column_stack([...]).
Read as. Build a matrix from columns.
Used for. Design matrices.
- Vertical stack
np.vstack([...]).
Read as. Stack arrays as rows.
Used for. Point-table construction.
- Diagonal matrix
np.diag(s).
Read as. Put vector entries on the diagonal.
Used for. SVD reconstruction.
- Sample grid
np.linspace(a, b, N).
Read as. Evenly spaced sample points.
Used for. Plotting and sampling.
- Trapezoid rule
np.trapezoid(values, grid).
Read as. Approximate an integral from samples.
Used for. Polynomial inner products.
- Numerical rank
np.linalg.matrix_rank(A).
Read as. Numerical rank.
Used for. Independent directions.
- Determinant
np.linalg.det(A).
Read as. Determinant of a square matrix.
Used for. Invertibility checks.
- Least squares
np.linalg.lstsq(A, b, rcond=None)[0].
Read as. Least-squares coefficients.
Used for. Regression, projection, and sampled polynomial approximation.
- Residual orthogonality
A.T @ r.
Read as. Dot products with the columns of
\(A\text{.}\) Used for. Least-squares residual checks.
- Linear solve
np.linalg.solve(A, b).
Read as. Solve a square nonsingular system.
Used for. Linear systems.
- General eigenvalues
np.linalg.eig(H).
Read as. Eigenvalues and eigenvectors.
Used for. General square matrices.
- Symmetric eigenvalues
np.linalg.eigvalsh(H).
Read as. Eigenvalues of a symmetric matrix.
Used for. Hessian classification.
- Symmetric eigenvectors
np.linalg.eigh(B).
Read as. Symmetric eigenvalues and eigenvectors.
Used for. Spectral and SVD-related computations.
- QR factorization
np.linalg.qr(A).
Read as. QR factorization.
Used for. Least-squares checks.
- SVD
np.linalg.svd(A, full_matrices=False).
Read as. SVD.
Used for. Compression.
- Sampled powers
xs**2,
xs**3.
Read as. Sampled powers of
\(x\text{.}\) Used for. Polynomial feature columns.
- Sampled product
xx*yy.
Read as. Entrywise product of sampled
\(x\)- and
\(y\)-coordinates.
Used for. Two-variable polynomial features.
- Two-variable grid
np.meshgrid(grid, grid).
Read as. Coordinate arrays for a rectangular sample grid.
Used for. Two-variable sampled fits.
- Flatten grid
X.ravel().
Read as. Flatten an array into one dimension.
Used for. Turning grid coordinates into sample lists.
- Fitted sampled values
A @ c.
Read as. Fitted sampled values.
Used for. Polynomial least-squares fits.
- Residual vector
y - A @ c.
Read as. Residual vector.
Used for. Residual-orthogonality checks.
- Quadratic form
h @ H @ h.
Read as. Quadratic form
\(\mathbf h^T H\mathbf h\text{.}\) Used for. Hessian quadratic forms.
Python helper patterns. See
B.12.
- Define function
def f(...):.
Read as. Define a helper function.
Used for. Repeated computations.
- Return value
return ....
Read as. Output from a function.
Used for. Helper functions.
- Loop
for k in range(n):.
Read as. Repeat an indented block.
Used for. Iterative algorithms.
- Append
losses.append(...).
Read as. Add one item to a list.
Used for. Recording histories.
- Plain number
float(...).
Read as. Convert to a scalar.
Used for. Cleaner output.
- List comprehension
[f(x) for x in values].
Read as. Build a list by looping.
Used for. Compact repeated calculations.
- Dictionary comprehension
{k: v for ...}.
Read as. Build a dictionary by looping.
Used for. Comparing parameter choices.
- Pairing
zip(a, b).
Read as. Pair entries from two iterables.
Used for. Labeled loops.
- Dictionary
dict(...).
Read as. Build a dictionary.
Used for. Named results.
- Length
len(values).
Read as. Count entries.
Used for. Sizes and loops.
- Round
round(x, 3).
Read as. Round a Python number.
Used for. Readable output.
- Print
print(...).
Read as. Display a value.
Used for. Notebook output.
- Assert
assert condition.
Read as. Check that a condition holds.
Used for. Lab sanity checks.
Optional attention, SymPy, checks, and plotting. See
B.11,
B.9,
B.13, and
B.14.
- Upper triangle
np.triu(..., k=1).
Read as. Upper-triangular part above the diagonal.
Used for. Causal mask.
- Boolean mask
.astype(bool).
Read as. Convert to Boolean mask.
Used for. Optional attention.
- Copy
.copy().
Read as. Make an independent copy.
Used for. Optional attention.
- Mask assignment
S_masked[mask] = -1e9.
Read as. Change selected entries.
Used for. Optional attention masks.
- Row normalization
e / e.sum(axis=1, keepdims=True).
Read as. Divide each row by its row sum.
Used for. Softmax rows.
- Symbols
sp.symbols("x y").
Read as. Create symbolic variables.
Used for. SymPy formulas.
- Symbolic matrix
sp.Matrix([...]).
Read as. Symbolic matrix or vector.
Used for. SymPy.
- Symbolic identity
sp.eye(n).
Read as. SymPy identity matrix.
Used for. Exact examples.
- Derivative
sp.diff(f, x).
Read as. Symbolic derivative.
Used for. Exact derivative checks.
- Jacobian
F.jacobian([x, y]).
Read as. Symbolic Jacobian.
Used for. Local linearization.
- Substitution
J.subs({...}).
Read as. Substitute values.
Used for. Jacobian at a point.
- NumPy conversion
np.array(..., dtype=float).
Read as. Convert symbolic output to NumPy.
Used for. Numerical multiplication.
- Row reduction
M.rref().
Read as. Reduced row echelon form and pivots.
Used for. Exact pivot analysis.
- Nullspace
M.nullspace().
Read as. List of symbolic column-vector basis elements.
Used for. Exact null spaces.
- Scalar closeness
np.isclose(a, b).
Read as. Approximate scalar equality.
Used for. Numerical checks.
- Approximate equality
np.allclose(x, y).
Read as. Approximate equality.
Used for. Numerical checks.
- Rounded display
np.round(x, 3).
Read as. Round an array for display.
Used for. Readable output.
- Figure setup
plt.figure(...).
Read as. Start a figure.
Used for. Optional plots.
- Figure and axes
plt.subplots(...).
Read as. Start a figure and axes pair.
Used for. Optional plots.
- Matrix image
plt.imshow(A).
Read as. Display a matrix as an image.
Used for. Optional attention plots.
- Color scale
plt.colorbar(...).
Read as. Add a scale bar.
Used for. Matrix image interpretation.
- Plot labels
plt.title(...),
plt.xlabel(...),
plt.ylabel(...).
Read as. Add labels.
Used for. Readable plots.
- Tick labels
plt.xticks(...),
plt.yticks(...).
Read as. Add tick labels.
Used for. Token labels.
- Line plot
plt.plot(...).
Read as. Draw connected points or curves.
Used for. Optional geometry plots.
- Equal scales
plt.axis("equal").
Read as. Use equal horizontal and vertical scales.
Used for. Optional geometry plots.
- Grid
plt.grid(True).
Read as. Show a background grid.
Used for. Optional geometry plots.
- Legend
plt.legend().
Read as. Show plot labels.
Used for. Optional geometry plots.
- Display figure
plt.show().
Read as. Display the figure.
Used for. Notebooks.