Manifold Matrices: Mental Models for Dimensional Arrays
This is an extension of my reflections in Things I Wish My Coding Teachers Taught Me.
When learning about nested for loops, the standard Computer Science curriculum often abstracts them as nested counting operations. But if you map those loops spatially, they aren’t timelines—they are geometric generators.
Each time you nest a loop, you add an axis. A single loop is a 1D displacement (a line). A nested loop creates a 2D manifold (a plane). With three loops, the code literally becomes a 3-dimensional object itself, displacing energy until it reaches the spatial stopping point (the bounds) of that higher-dimensional manifold.
for (int z = 0; z < depth; z++) {
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
// Your coordinate logic here
}
}
}
When you visualize code this way, two very simple but distinct mental models emerge that can help map out how multi-dimensional arrays actually function depending on how you read the z axis.
1. The 3D Printing Model (Voxel Grids and Boundary Representations)
If you map the outermost z loop as physical depth, the structure becomes directly comparable to 3D printing.
In this model, the matrix provides the fine coordinate points. The outer condition bounds define the geometry’s shell—which in computer graphics is known as a Boundary Representation (B-rep). The inner layers define the internal volume (or the infill).
If you render the boundaries as [X] and the internal volume as [ ], iterating through the loops natively carves out an interior structure layer by layer:
X = The outer boundary (the shell of the manifold)
. = The internal volume (the enclosed dimensional space)
-- Depth Layer z=0 --
[X] [X] [X] [X] [X]
[X] [X] [X] [X] [X]
[X] [X] [X] [X] [X]
[X] [X] [X] [X] [X]
[X] [X] [X] [X] [X]
-- Depth Layer z=1 --
[X] [X] [X] [X] [X]
[X] [.] [.] [.] [X]
[X] [.] [.] [.] [X]
[X] [.] [.] [.] [X]
[X] [X] [X] [X] [X]
-- Depth Layer z=2 --
[X] [X] [X] [X] [X]
[X] [.] [.] [.] [X]
[X] [.] [.] [.] [X]
[X] [.] [.] [.] [X]
[X] [X] [X] [X] [X]
-- Depth Layer z=3 --
[X] [X] [X] [X] [X]
[X] [.] [.] [.] [X]
[X] [.] [.] [.] [X]
[X] [.] [.] [.] [X]
[X] [X] [X] [X] [X]
-- Depth Layer z=4 --
[X] [X] [X] [X] [X]
[X] [X] [X] [X] [X]
[X] [X] [X] [X] [X]
[X] [X] [X] [X] [X]
[X] [X] [X] [X] [X]
Manifold closed at boundary x=4, y=4, z=4.
Just like a physical object, if you only iterate two depth layers (z=0 and z=1), you are basically just putting a front wall and a back wall together. Topologically, it is only 2.5D. It takes 4 or 5 depth layers to create enough structural volume to have a true “inside” versus an “outside.”
Once you visualize the volume, an if statement to omit logic isn’t an abstract skip—it’s just carving a window or a hallway right through the array structure.
2. The Time Series Model
There is a second connection you can make to completely shift how you read the data.
What happens if we take that exact same 3D shape, but mentally turn it on its side?
Instead of stacking the depth frames physically front-to-back, we lay them out from left-to-right. The z axis stops representing physical depth and instantly becomes a local model of time—a Time Series. You are no longer looking at a static 3D geometric cube. You are looking at a 2D grid that morphs its state across frames. The computation is just tracking the data inside the internal volume frame-by-frame, recording changes over time.
This specific perspective gives a lot of insight into why mapping logic out on grid or graph paper can be so helpful for debugging. However, even graph paper is ultimately limiting because it is static. To be entirely honest, for the longest time I believed I simply wasn’t good at math and there was no point in getting better. My reasoning has always been visual and spatial, built purely on geometric dynamics, and classical math classes almost never accommodate that.
It wasn’t until I read the first two chapters of Dynamics: The Geometry of Behavior by Ralph H. Abraham and Christopher D. Shaw that things clicked. The book didn’t fundamentally shift my perspective, but it gave me the exact terminology and a mathematical framework that proved my intuition was entirely valid. I already knew how to read standard, flat statistical X-Y plots, but they never mapped to the dimensional way my mind worked. Dynamics skips the flat graphs and visualizes a time series as a state-space trajectory—literally plotting a system as a squiggly line tracing its path through a multidimensional box. It finally gave me the vocabulary to describe what I was naturally picturing: tracking spatial datapoints from an origin 0 to an end state, like hitmarks leaving leading trails across a physical grid.
It validated my visual thinking as a mathematically sound way to model computation, which is why it remains one of my absolute favorite math books.
By just shifting how you read that third loop axis—from a physical depth to a local time series—you transition from rendering a static solid shape to tracking dynamic states. Keeping these two simple mental models in your pocket makes interpreting the logic of nested structures much easier to visualize.