I'm curious if anyone recalls the decode (⊥) function in APL? It was useful to translate between dimensions in an n-dimensional array and a flattened equivalent.
For example, if I had a 4 dimensional array, I could use decode as follows to derive the location in a flattened file:
A = 4 x 5 x 2 x 11 is a 4-d array
B = 440 element flattened version of A
4 5 2 11 decode 1 2 1 3 = 110 + 44 + 11 + 3 = 168th element of B
I recall that I had to add ±1 depending on index root.
I should note...decode is quite easy. It's actually the encode (⊤) equivalent (to move from a flat file index back to the array indices) that is useful to me. So how to move from the 168th element back to [1, 2, 1, 3]?