Hello,
there is relevant discussion and a sketch how to implement something like 
this at
http://stackoverflow.com/questions/30159815/is-there-a-julia-equivalent-to-numpys-ellipsis-slicing-syntax/30163887#30163887
and
https://github.com/JuliaLang/julia/issues/5405


Am Dienstag, 22. März 2016 13:10:56 UTC+1 schrieb Luke Stagner:
>
> Hello,
>
> I've recently come across a situation where I needed to index an array 
> a[:,:,i,j]
>
> without having to know how many colons I needed.
>
> I accomplished this with the following code.
> function recursive_slicedim(A,dims,inds)
>     d_len = length(dims)
>     s = slicedim(A,dims[d_len],inds[d_len])
>     if d_len != 1
>         return recursive_slicedim(s,dims[1:d_len-1],inds[1:d_len-1])
>     else
>         return s
>     end
> end
>
> function tail_index(A,inds)
>     s_len = length(size(A))
>     i_len = length(inds)
>     dims = tuple([s_len - i for i=i_len-1:-1:0]...)
>
>     return squeeze(recursive_slicedim(A,dims,inds),dims)
> end
>
> a = rand(2,2,2,2)
> tail_index(a,(1,2)) == a[:,:,1,2]
>
> b = rand(2,2,2)
> tail_index(b,(1,2)) == b[:,1,2]
>
> Does something like this already exist in Base? 
> How would I go about writing some syntactic sugar for this function?
> Something like 
> a[*,1,2] == last_index(a,(1,2))
>
>
>
>

Reply via email to