I have two ndarrays of size (m x n), and two lists of length m and n respectively. I want to convert the two matrices to a dataframe with four columns. The first two columns correspond to the m and n dimensions, and contain the values from the lists. The next two columns should contain the values from the two matrices. In total, the resulting dataframe should have m times n rows.
Example: If these are the two matrices and two lists,
a1 = np.array([[1, 2], [3, 4],[5,6]])
a2 = np.array([[10, 20], [30, 40],[50,60]])
l1 = [5,7,99]
l2 = [2,3]
then the resulting dataframe should look like this:
"l1" "l2" "a1" "a2"
5 2 1 10
7 2 3 30
99 2 5 50
5 3 2 20
7 3 4 40
99 3 6 60
The order of the rows does not matter.
Although I only have two matrices in this specific case, I am curious about a solution which is easily applicable to any number of same size matrices.