How to create a (n-1) dimensional view of a n dimensional array in a general way?

For the n-dimensional array, I can do it separately

A[:, 1]  # for 2D
A[:, :, 1]  # for 3D
A[:, :, :, 1]  # for 4D

but how can I do it generally if n is not known in advance? i.e. the number of colons is unknown.

using Base.Iterators
A[repeated(:,ndims(A)-1)..., 1]

or with EllipsisNotation.jl:

A[.., 1]
1 Like

Ah, thanks! Follow your suggestions, I also come up with another solution

A[fill(:, ndimis(A)-1)..., 1]