Complete worked example
python
import numpy as np
def inspect_example(first, second, weights):
x = np.asarray(first, dtype=np.float64)
y = np.asarray(second, dtype=np.float64)
coefficients = np.asarray(weights, dtype=np.float64)
if x.ndim != 1 or x.shape != y.shape or coefficients.shape != (2,):
raise ValueError("expected two aligned feature vectors and two weights")
if not all(np.isfinite(a).all() for a in (x, y, coefficients)):
raise ValueError("expected finite numerical inputs")
features = np.column_stack((x, y))
return features @ coefficients- Reasoning
- The worked function uses column_stack((first, second)) to construct a matrix shaped (observations, 2). A weight vector shaped (2,) then produces one value per observation through features @ weights. Trace one output as first[i] * weights[0] plus second[i] * weights[1]. This is different from features * weights, which broadcasts weights but retains one product per feature. A matrix product can combine known coefficients without fitting a machine-learning model. The weights here are supplied synthetic values, not learned estimates or validated hiring predictions. Later ML lessons will discuss how coefficients are selected and evaluated; this array lesson establishes their shape and alignment first.