Preserving the dimensions of a slice from a Numpy 3d array
Posted
by Brendan
on Stack Overflow
See other posts from Stack Overflow
or by Brendan
Published on 2010-04-14T18:50:40Z
Indexed on
2010/04/14
18:53 UTC
Read the original article
Hit count: 284
I have a 3d array, a
, of shape say a.shape = (10, 10, 10)
When slicing, the dimensions are squeezed
automatically i.e.
a[:,:,5].shape = (10, 10)
I'd like to preserve the number of dimensions but also ensure that the dimension that was squeezed is the one that shows 1 i.e.
a[:,:,5].shape = (10, 10, 1)
I have thought of re-casting the array and passing ndmin
but that just adds the extra dimensions to the start of the shape tuple regardless of where the slice came from in the array a
.
© Stack Overflow or respective owner