# Arrays with two different types of indices

Is there a way of having arrays which have, so to speak, two different depths $m,n$? From the point of view of memory usage, it would be the same as an array of depth $m+n$, but I would like to obtain and treat the two depths and the respective dimension lists separately.

To use a mathematical analogy: a tensor (in geometry) of type $(1,2)$ is different than a tensor of type $(0,3)$, it has the same number of components, but the operations defined on the two differ.

How can I do this in Mathematica? Is there such a thing as a "doubly-deep" array? Or can I make a data structure, C-like, in which there is the actual array, plus a couple of int variables to keep track of the two different depths?

Update: Here is an example. Let $X$, $Y$, $Z$ be binary sets (= of 2 elements each). A transition matrix is a matrix whose rows sum to one. A transition matrix $A:X\times Y\to Z$ and a transition matrix $B:X\to Y\times Z$ would be then cubical arrays with the same number of entries (8), same depths (3) and dimensions (2,2,2), but different normalization. In particular: $$\sum_{x,y}A(x,y,z)=1 \quad\forall z\;,$$ but: $$\sum_{x}B(x,y,z)=1 \quad\forall y,z\;.$$ For example I would like to define a command, say "CheckNormal", that checks if $A$ and $B$ are correctly normalized. But the normalizations differ. It's as if $A$ had "depth" (2,1), and "dimensions" ((2,2),(2)), and $B$ had depth (1,2), and dimensions ((2),(2,2)). In both cases, I want the sums to be executed only over the first set of indices, and I would like that information (= how many indices are in the first set) to be encoded in $A$ and $B$ (not in the function CheckNormal).
• ArrayReshape[ ]? – Dr. belisarius Oct 6 '15 at 14:16
• Could you give us a practical example of the structure of an array that would fit your requirements? ArrayReshape as suggested by @belisarius is not limited to two dimensions... – MarcoB Oct 6 '15 at 14:37
• Transpose works in any number of dimensions, and allows any permutation of the different levels. – bill s Oct 6 '15 at 14:57
• My feeling is that the best way to implement this is via the operations on the arrays, not in the arrays themselves; you would need different operations (CheckNormalTypeA, CheckNormalTypeB). Alternatively, use customs Heads typeA and tybeB that wrap your (equal-dimensional) arrays, and then overload the definition of CheckNormal using something like CheckNormal[a_typeA] := ..., etc. However, it certainly seems like ArrayReshape is the way to go, based on your ((2,2),(2) to ((2),(2,2)) example. – march Oct 6 '15 at 15:24