How to stop array slice being flattened

Julia is removing singular dimensions when I slice an array:

A = reshape([2 2 2 2], 2, 1, 2)
A[1,1,:]
2-element Vector{Int64}:
 2
 2

If I want A to remain a 1x1x2 array, is there anything I can do other than reshape it again?

Is:

julia> A[1:1,1:1,:]
1×1×2 Array{Int64, 3}:
[:, :, 1] =
 2

[:, :, 2] =
 2

good enough?
General idea: indexing with a single index and not a range removes a dimension from the output.

5 Likes

Yes. Thanks, Dan.