I have a list with dimensions {1000, 1000, 1}
and I would like it to have dimensions {1000, 1000}
. But Flatten[list,1]
makes it {1000000, 1}
and I've also tried Flatten[list,-1]
with no success. Can I use flatten to do this or will I need a different command?
1 Answer
Given a list of similar shape to the one in the question:
$a = Array[a[##] &, {3, 3, 1}];
$a // MatrixForm
... we can tell Flatten
to leave level one untouched but flatten levels two and three together:
Flatten[$a, {{1}, {2, 3}}] // MatrixForm
This syntax is the subject of the question Flatten command: matrix as second argument.
Flatten /@ list
? $\endgroup$list[[All, All, 1]]
will work. $\endgroup$Flatten[list, {1, 3}]
also works, butArrayReshape[list, Most@Dimensions@list]
might be fastest. $\endgroup$