[Numpy-discussion] Array slices and number of dimensions

Warren Weckesser warren.weckesser@enthought....
Wed Sep 1 16:59:53 CDT 2010


Thomas Robitaille wrote:
> Hi,
>
> I'm trying to extract sub-sections of a multidimensional array while keeping the number of dimensions the same. If I just select a specific element along a given direction, then the number of dimensions goes down by one:
>
>   
> <snip>
>  In fact, I can get what I want by doing:
>
>   
>>>> a[[0],:,:][:,:,[5]].shape
>>>>         
> (1, 10, 1)
>
> so I can get around the issue

You can also use "trivial" slices:

In [2]: a = np.zeros((10,10,10))

In [3]: a.shape
Out[3]: (10, 10, 10)

In [4]: a[0:1, :, 5:6].shape
Out[4]: (1, 10, 1)



Warren


> , but just wanted to check whether the issue with a[[0],:,[5]] is a bug?
>
> Thanks,
>
> Tom
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>   



More information about the NumPy-Discussion mailing list