If a
is a multi-dimensional array, a[..., j]
gives an array of shape a.shape[:-1]
. So, for example if a
is a m
-by-n
matrix a[..., j]
gives an m
dimensional vector of shape (m,)
. What is the correct way to do the above-mentioned slicing such that the result has the same number of dimensions as a
with the last dimension having size 1
. For example a[<magical_slice>]
for the m
-by-n
array should give a (column) vector of shape (m, 1)
.
Currently I am using
a[..., j].rehape(a.shape[:-1] + (1,))
To achieve that goal. However, that looks too complicated (and most probably inefficient) for what I would like to do.