AI Grounds
Open AI Grounds on a desktop
These interactive lessons need a larger screen. Please continue on a desktop or laptop computer.
AI Grounds
These interactive lessons need a larger screen. Please continue on a desktop or laptop computer.
Guided discovery
Align the axes. Trace one output value.
Shape lists the sizes of an array’s axes; rank is the number of axes. This lab keeps rank 3. Axis −1 is last, −2 is middle and −3 is first. Each size can be an integer from 1 through 5.
Equal sizes OR one size is 1. Every axis must pass. Each compatible pair below gives a candidate axis size; the final output exists only when no pair fails.
| Axis | A size | B size | Candidate size | Rule |
|---|---|---|---|---|
| -1 | 1 | 4 | 4 | A reuses index 0 (size 1 → 4) |
| -2 | 3 | 3 | 3 | Same size |
| -3 | 2 | 3 | Unavailable | Incompatible: unequal and neither is 1 |
Failed axes: -3. No output shape or output value exists.
One output axis for each aligned pair, if all pairs pass.
Unavailable
Unequal non-singleton sizes block the operation
Repair each failed axis before tracing a value.
Number of elements in the resulting array.
Unavailable
No resulting array
Elementwise C = A + B, not matrix multiplication.
No output value exists until all aligned axes are compatible.
All five possible B sizes for the current A axis −3 = 2. Either side may supply size 1.
| B axis −3 | Candidate size | Rule | Current |
|---|---|---|---|
| 1 | 2 | B reuses index 0 (size 1 → 2) | |
| 2 | 2 | Same size | |
| 3 | Unavailable | Incompatible: unequal and neither is 1 | Selected |
| 4 | Unavailable | Incompatible: unequal and neither is 1 | |
| 5 | Unavailable | Incompatible: unequal and neither is 1 |
In general, ranks can differ. Align from the right and treat missing leading axes as size 1. For A [3,1] and B [2,3,4], align A as [1,3,1]: all pairs pass, giving output [2,3,4]. This lab’s editable arrays retain three axes.
Broadcasting logically reuses source values without requiring tiled input copies. An addition result can allocate output memory; broadcasting does not make the result cost-free. It does not change stored input shapes. Size-0 axes are outside these controls.
A [2, 3, 1], B [3, 3, 4]. Incompatible shapes; no output value.