# creating a data framework using matrix tensor

I want to create a data framework using matrix tensor. The framework should have the following features:

1. An (n,n) matrix, m[t;i,j], indexed by t=1,2,...,T;
2. For each element [t;i,j] of m, create k more matrices, m[t;i,j;k], each with the dimension (n,n).
3. Notations: t denotes time; [i,j], matrix cell, and k, the number of sub-matrices coupled with m[t;i,j].

I should be able to retrieve pairs of the coupled matrices across time t and for each element [i,j]. Suppose that I want to get the data for t=3 and t=7 for elements [2,1] and [3,2] and k=3, which is a total of 12 matrices. Each one of these 12 matrices is of (n,n) dimension.

This is quite complicated for me but creating a matrix tensor m[t; i,j; k] would make my life easier (with your help of course). Note that the tensor should accept the list of elements such as {1,4,6,8..} for t, {(1,3), (2,1),...} for [i,j] and {1,2,...} for k.

I hope someone can help me in building this data framework.

EDIT 1

Here is a visual matrix tensor for t=1, n=2 and k=2. This matrix has been constructed using Table in a very primitive way, therefore I only give you the matrix I was imagining.

Original matrix mat and individual matrices for each element of mat are:

and the final data framework is:

Blue sub-matrix (consisting of 2 matrices k1 and k2) in the first column corresponds to cell a[1,1] of matrix mat; green sub-matrix (consisting of k1 and k2) in the first column corresponds to cella[2,1] of mat; similarly, pink sub-matrix in the 2nd column of mat is associated with a[1,2] of 'mat and so on. This final big matrix is only for t=1.

• can you post a concrete example of the desired result for t=1, n=2, k=2, ij =Tuples[Range[3], 2]? – kglr Oct 18 '18 at 22:13
• @kglr: I will post an example in a few minutes. Thanks. – Tugrul Temel Oct 18 '18 at 22:22
• Looks like you can use bigmat = KroneckerProduct[ConstantArray[1, {n, n}], Array[Subscript[a, #][##2] &, {k, n, n}]]. How would t enter the picture; that is, how would bigmat change when t=5? – kglr Oct 19 '18 at 4:08

ClearAll[mat]

$$\small\left( \begin{array}{cc} \left( \begin{array}{cc} a_1(1,1) & a_1(1,2) \\ a_1(2,1) & a_1(2,2) \\ \end{array} \right) & \left( \begin{array}{cc} a_1(1,1) & a_1(1,2) \\ a_1(2,1) & a_1(2,2) \\ \end{array} \right) \\ \left( \begin{array}{cc} a_2(1,1) & a_2(1,2) \\ a_2(2,1) & a_2(2,2) \\ \end{array} \right) & \left( \begin{array}{cc} a_2(1,1) & a_2(1,2) \\ a_2(2,1) & a_2(2,2) \\ \end{array} \right) \\ \left( \begin{array}{cc} a_3(1,1) & a_3(1,2) \\ a_3(2,1) & a_3(2,2) \\ \end{array} \right) & \left( \begin{array}{cc} a_3(1,1) & a_3(1,2) \\ a_3(2,1) & a_3(2,2) \\ \end{array} \right) \\ \left( \begin{array}{cc} a_1(1,1) & a_1(1,2) \\ a_1(2,1) & a_1(2,2) \\ \end{array} \right) & \left( \begin{array}{cc} a_1(1,1) & a_1(1,2) \\ a_1(2,1) & a_1(2,2) \\ \end{array} \right) \\ \left( \begin{array}{cc} a_2(1,1) & a_2(1,2) \\ a_2(2,1) & a_2(2,2) \\ \end{array} \right) & \left( \begin{array}{cc} a_2(1,1) & a_2(1,2) \\ a_2(2,1) & a_2(2,2) \\ \end{array} \right) \\ \left( \begin{array}{cc} a_3(1,1) & a_3(1,2) \\ a_3(2,1) & a_3(2,2) \\ \end{array} \right) & \left( \begin{array}{cc} a_3(1,1) & a_3(1,2) \\ a_3(2,1) & a_3(2,2) \\ \end{array} \right) \\ \end{array} \right)$$
• Yes, this is the main structure of the framework. This particular mat should have time index t because at each time t there is a new mat with the same dimension. How to retrieve the targeted data, for example, an element in mat[t=3, n=2, k=4] is also critical. – Tugrul Temel Oct 19 '18 at 9:24
• @Tugrul, is the following acceptable as the solution for the general case: matrix[t_, n_, k_] := Array[a[#][#2, #3][#4][##5] &, {t, n, n, k, n, n}]; for t = 3; n = 2; k = 3; and matrix[3, 2, 3] the whole structure and parts can be accessed using using Part, .e.g., matrix[3, 2, 3][[2, 1, 2, 3]]. – kglr Oct 19 '18 at 15:59
• Very neat work. I will work on it with an example to learn how to enter data in it. Can I use Rule` to enter observations in the data framework? Any idea about the easiest way to enter data? Thanks very much for this marvelous code. – Tugrul Temel Oct 19 '18 at 16:35