# Selecting elements of sublists or reshaping a list of lists

I have this list

{{{0.05792, 0.31744}, 0., 0., 0., 0.,
0.}, {0., {0.28832, 0.49024}, {0.17173, 0.386393}, 0., 0.,
0.}, {0., {0.17173, 0.386393}, {0.104, 0.352}, 0., 0., 0.}, {0., 0.,
0., {0.30752, 0.38464}, {0.322232, 0.260264}, {0.214663,
0.107331}}, {0., 0.,
0., {0.322232, 0.260264}, {0.392, 0.496}, {0.277128,
0.415692}}, {0., 0.,
0., {0.214663, 0.107331}, {0.277128, 0.415692}, {0.2, 0.4}}}


or in the matrix form:

I would like to convert this list to a list of two matrices, each of the same size as the input matrix, i.e. 6 by 6, where the non-zero entries for the first matrix are given by the first element of the lists in the input matrix and the same for the second matrix.

If it helps I can also create a matrix where the zeros are replaced by a list of two zeros to match the dimension.

lst1=#1&@@@#&/@lst


{{0.05792, 0., 0., 0., 0., 0.}, {0., 0.28832, 0.17173, 0., 0., 0.},

{0., 0.17173, 0.104, 0., 0., 0.}, {0., 0., 0., 0.30752, 0.322232, 0.214663},

{0., 0., 0., 0.322232, 0.392, 0.277128}, {0., 0., 0., 0.214663, 0.277128, 0.2}}

lst2=#2&@@@#&/@lst


{{0.31744, 0., 0., 0., 0., 0.}, {0., 0.49024, 0.386393, 0., 0., 0.},

{0., 0.386393, 0.352, 0., 0., 0.}, {0., 0., 0., 0.38464, 0.260264, 0.107331},

{0., 0., 0., 0.260264, 0.496, 0.415692}, {0., 0., 0., 0.107331, 0.415692, 0.4}}

f = Thread @* Map[Thread];


With listsas your input list:

MatrixForm /@ f[lists]


Alternatively, you can replace 0. with {0., 0.} in lists

paddedlists = lists /. 0. -> {0., 0.};


and use paddedlists with Transpose or with Flatten to get the same result:

f @ lists == Flatten[paddedlists, {{3}, {2}, {1}}] == Transpose[paddedlists, {3, 2, 1}]

True

• Thank you! Exactly what I wanted! May 31 at 6:26