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?
Asked
Active
Viewed 464 times
2
anderstood
- 14,301
- 2
- 29
- 80
user13948
- 225
- 1
- 5
1 Answers
0
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.
WReach
- 68,832
- 4
- 164
- 269


Flatten /@ list? – anderstood Feb 19 '18 at 16:17list[[All, All, 1]]will work. – Carl Woll Feb 19 '18 at 16:34Flatten[list, {1, 3}]also works, butArrayReshape[list, Most@Dimensions@list]might be fastest. – Michael E2 Feb 19 '18 at 17:12