Preserving the dimensions of a slice from a Numpy 3d array

后端 未结 1 410
栀梦
栀梦 2020-12-16 23:34

I have a 3d array, a, of shape say a.shape = (10, 10, 10)

When slicing, the dimensions are squeezed automatically i.e.

相关标签:
1条回答
  • 2020-12-17 00:10
    a[:,:,[5]].shape
    # (10,10,1)
    

    a[:,:,5] is an example of basic slicing.

    a[:,:,[5]] is an example of integer array indexing -- combined with basic slicing. When using integer array indexing the resultant shape is always "identical to the (broadcast) indexing array shapes". Since [5] (as an array) has shape (1,), a[:,:,[5]] ends up having shape (10,10,1).

    0 讨论(0)
提交回复
热议问题