FIELD NOTES

ML Foundations

The ideas underneath the implementation.

ML Foundations

1 MIN READ

Require ASCII digits in an identifier

Python's str.isdecimal accepts Unicode decimal characters; combine it with isascii when an identifier requires ASCII digits.

2026-11-13

ML Foundations

1 MIN READ

Python statistics.quantiles changed its one-sample rule

Python 3.12 raises StatisticsError for a one-value input to statistics.quantiles; Python 3.13 changed that behavior. Check the supported runtime when handling tiny samples.

2026-11-12

ML Foundations

1 MIN READ

Python itertools.batched keeps a short final batch

itertools.batched groups an iterable into tuples of size n, but the final tuple may be shorter. Add an explicit check if downstream code requires equal batch sizes.

2026-11-12

ML Foundations

1 MIN READ

Python dict views stay live; lists are snapshots

dict.keys(), values(), and items() return dynamic views. Materialize a list when you need the entries captured at one point in time.

2026-11-12

ML Foundations

2 MIN READ

Python cache is thread-safe but not single-flight

functools.cache keeps its internal mapping coherent across threads, but simultaneous misses may call the wrapped function more than once.

2026-11-12

ML Foundations

1 MIN READ

Why numpy.take flattens by default

When axis is omitted, numpy.take indexes the flattened array. Pass an axis to select along rows or columns without crossing row boundaries.

2026-11-12

ML Foundations

2 MIN READ

Set NumPy digitize right to control bin-edge ownership

For increasing bins, numpy.digitize(right=False) includes the left edge and excludes the right. Toggle right when your interval convention requires the opposite.

2026-11-12

ML Foundations

2 MIN READ

Choose NumPy meshgrid indexing to match your axis order

NumPy meshgrid defaults to Cartesian xy indexing, which swaps the first two dimensions. Use indexing="ij" when output axes should follow input coordinate vectors.

2026-11-11

ML Foundations

2 MIN READ

Use NumPy empty only when you overwrite every element

numpy.empty returns uninitialized values. Allocate with it only when your code writes every slot before any read; otherwise choose an initialized constructor such as zeros.

2026-11-11

ML Foundations

1 MIN READ

Edit a NumPy broadcast view safely

Understand why broadcast_to is read-only and make a writable copy for independent channel edits.

2026-11-09

ML Foundations

2 MIN READ

Keep probability 1.0 in the final histogram bin

A searchsorted bin-ID calculation needs an explicit final-edge rule to match NumPy histogram. Validate the score range before adjusting that endpoint.

2026-10-26

ML Foundations

2 MIN READ

Why pooled out-of-fold R2 can hide poor fold scores

Concatenating held-out predictions changes the target-mean baseline used by R2. Inspect fold scores and residual sums before treating pooled R2 as mean cross-validation performance.

2026-10-26

ML Foundations

1 MIN READ

Make NumPy top-k results deterministic when scores tie

argpartition selects a boundary efficiently, but tied values can leave membership or order unspecified. Add an explicit key when repeatable top-k output matters.

2026-10-25

ML Foundations

2 MIN READ

When a NumPy sum wraps in a narrow integer dtype

NumPy reductions can return a wrapped integer when the accumulator dtype is too small; check the range and choose the accumulator deliberately.

2026-10-24

ML Foundations

2 MIN READ

Make file-based ML splits repeatable

Filesystem iteration order is not guaranteed. Sort a fixed file list before position-based splits, and persist assignments when the dataset changes.

2026-10-24

ML Foundations

2 MIN READ

Why averaging batch means misweights the last batch

A smaller final batch can distort an epoch loss when every batch mean gets equal weight. Use the denominator that matches the loss you mean to report.

2026-10-22

ML Foundations

3 MIN READ

When NumPy broadcasting gives you the wrong loss

A shape-compatible operation can still compare the wrong values. Diagnose a silent pairwise-error bug before it reaches your metrics.

2026-10-21