Numpy slice of arbitrary dimensions

前端 未结 3 1915
南方客
南方客 2020-12-08 03:35

I would like to slice a numpy array to obtain the i-th index in the last dimension. For a 3D array, this would be:

slice = myarray[:,:,i]

B

3条回答
  •  执笔经年
    2020-12-08 04:33

    There is ... or Ellipsis, which does exactly this:

    slice = myarray[..., i]
    

    Ellipsis is the python object, if you should want to use it outside the square bracket notation.

提交回复
热议问题