# Two problems in list manipulation

I have a 3 by 3 matrix, in which each element is a 2 by 1 matrix.

1. How can I get rid of the zeros and change my matrix to a 3 by 3 matrix in which each element is a number?

2. How can I keep the zeros and just change the 3 by 3 matrix to a 3 by 6 Matrix (get rid of the internal matrix forms and just keep the numbers)?

 {{{0., 0.0516705 Subscript[a, i, 1]}, {0., -0.0499662 Subscript[a, i, 2]},
{0., 0.0189977 Subscript[a, i, 3]}},
{{0., -0.0499662 Subscript[a, i, 1]}, {0., 0.0706682 Subscript[a, i, 2]},
{0., -0.0539635 Subscript[a, i, 3]}},
{{0., 0.0189977 Subscript[a, i, 1]}, {0., -0.0539635 Subscript[a, i, 2]},
{0., 0.0741863 Subscript[a, i, 3]}}}

• mat[[All, All, 2]], maybe. And look up ArrayReshape[mat, {3, 6}] to see if it does what you want. – Michael E2 Jun 10 '17 at 22:31
• @MichaelE2 Thank you Michael, It works. :) – Delaram Nematollahi Jun 10 '17 at 22:53

## 1 Answer

This is record as an answer the solution given by MichaelE2 in a comment.

m =
{{{0., 0.0516705 Subscript[a, i, 1]}, {0., -0.0499662 Subscript[a, i, 2]},
{0., 0.0189977 Subscript[a, i, 3]}},
{{0., -0.0499662 Subscript[a, i, 1]}, {0., 0.0706682 Subscript[a, i, 2]},
{0., -0.0539635 Subscript[a, i, 3]}},
{{0., 0.0189977 Subscript[a, i, 1]}, {0., -0.0539635 Subscript[a, i, 2]},
{0., 0.0741863 Subscript[a, i, 3]}}};

m1 = m[[All, All, 2]]

{{0.0516705 Subscript[a, i, 1], -0.0499662 Subscript[a, i, 2],
0.0189977 Subscript[a, i, 3]},
{-0.0499662 Subscript[a, i, 1], 0.0706682 Subscript[a, i, 2],
-0.0539635 Subscript[a, i, 3]},
{0.0189977 Subscript[a, i, 1], -0.0539635 Subscript[a, i, 2],
0.0741863 Subscript[a, i, 3]}}

m2 = ArrayReshape[m, {3, 6}]

{{0., 0.0516705 Subscript[a, i, 1], 0., -0.0499662 Subscript[a, i, 2],
0., 0.0189977 Subscript[a, i, 3]},
{0., -0.0499662 Subscript[a, i, 1], 0., 0.0706682 Subscript[a, i, 2],
0., -0.0539635 Subscript[a, i, 3]},
{0., 0.0189977 Subscript[a, i, 1], 0., -0.0539635 Subscript[a, i, 2],
0., 0.0741863 Subscript[a, i, 3]}}