Scale the Table
Broadcast 1D column minimums and spans across an entire N-by-D feature matrix and examine outlier compression.
The problem
Scaling one row at a time in a loop obscures the matrix structure of preprocessing. Given a four-row, three-column training table [[10, 100, 2], [20, 500, 8], [30, 300, 6], [50, 900, 10]], tensor broadcasting subtracts the 1D column-minimum vector from every row at once and divides by the 1D column-span vector in a single expression.
Two mistakes commonly corrupt full-table scaling: collapsing the whole matrix to one global scalar minimum and maximum instead of keeping one pair per column, and overlooking how one extreme value in a column compresses every other row in that column toward zero.
Work through the numbers
Compute per-column bounds down axis . Column ([10, 20, 30, 50]) has and span . Column ([100, 500, 300, 900]) has and span . Column ([2, 8, 6, 10]) has and span .
Broadcast across all four rows. Row sits at all three minimums and becomes [0, 0, 0]. Row ([20, 500, 8]) becomes [0.25, 0.5, 0.75]. Row ([30, 300, 6]) becomes [0.5, 0.25, 0.5]. Row sits at all three maximums and becomes [1, 1, 1].
Now watch what happens to column if row 's raw value of jumps by an outlier_add offset. Adding raises column 's maximum to (span ), halving rows and in column from [0.5, 0.25] down to [0.25, 0.125]. Adding raises the maximum to (span ), squashing rows and to [0.125, 0.0625].
The live model
The grid draws one cell bar per entry of the scaled matrix. At default outlier_add , interior rows and show distinct proportions [0.25, 0.5, 0.75] and [0.5, 0.25, 0.5] while rows and anchor [0, 0, 0] and [1, 1, 1]. Dragging outlier_add to and leaves columns and untouched while visibly compressing column 's interior bars toward .
![4 by 3 grid of unit bars showing scaled rows [0, 0, 0], [0.25, 0.5, 0.75], [0.5, 0.25, 0.5], and [1, 1, 1].](../assets/ml/scale-the-table--demo.png)
# Fix line width in scale-the-table--demo.lmc to stay well under 80 chars!
let outlier_add = scene.parameter("outlier_add", 0.0, 0.0, 2400.0, 800.0);
let z3 = "[[0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,1.0,0.0]]";
let bump = torch.tensor(z3, DType.F64);
let tbl = input + bump * outlier_add;
let lo = tbl.amin(0);
let hi = tbl.amax(0);
let answer = (tbl - lo).div(hi - lo);
out.set("scaled_table", answer);
{
"scaled_table": [
[
0,
0,
0
],
[
0.25,
0.5,
0.75
],
[
0.5,
0.25,
0.5
],
[
1,
1,
1
]
]
}Watch the parameter change
Your turn
The starter program collapses the entire matrix onto a single shared range, squashing columns and near zero instead of scaling each feature onto . Set answer to the matrix where every column is independently min-max scaled across rows; Check tests both the table above and unseen tables of varied shapes and scales.

let lo = input.min();
let hi = input.max();
let answer = (input - lo).div(hi - lo);
out.set("scaled_table", answer);
{
"scaled_table": [
[
0.008908685968819599,
0.1091314031180401,
0
],
[
0.0200445434298441,
0.5545657015590201,
0.0066815144766146995
],
[
0.031180400890868598,
0.33184855233853006,
0.004454342984409799
],
[
0.053452115812917596,
1,
0.008908685968819599
]
]
}Rescale every column of the 2D table input independently to [0, 1] using column-wise minimums and maximums.
Read the result carefully
Every non-constant column of a min-max scaled training matrix has exact minimum and exact maximum : if any column's minimum is nonzero or its maximum falls below , the reduction axis is wrong. Watch out for a constant column as well: span makes undefined, so drop the constant column or map it explicitly to .
At the same time, the outlier_add slider reveals min-max scaling's structural weakness. Because only two extreme rows pin the denominator , a single sensor spike or billionaire income in training crowds all typical observations into a narrow sliver near zero.
This book teaches min-max scaling, while standardization — subtracting the training mean and dividing by the training standard deviation via — is the usual alternative and is far less squeezed by one extreme value. Its mean and standard deviation are pinned on training rows exactly like and ; libraries differ in dividing variance by or , so always state which divisor you use.
Recap
- Tensor broadcasting min-max scales an table in one step via per column, provided no column is constant ().
- Global scalar bounds preserve cross-column unit imbalances instead of putting every feature on .
- When one extreme outlier squeezes min-max intervals, standardization ( pinned on training rows, stating versus ) is the standard alternative.